Skip to content

Commit

Permalink
feat(server): support selfhost licenses
Browse files Browse the repository at this point in the history
  • Loading branch information
forehalo committed Nov 27, 2024
1 parent 05a054c commit 7003581
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- CreateTable
CREATE TABLE "licenses" (
"key" VARCHAR NOT NULL,
"email" VARCHAR NOT NULL,
"stripe_subscription_id" VARCHAR,
"recurring" VARCHAR(20) NOT NULL,
"plan" VARCHAR(20) NOT NULL,
"variant" VARCHAR(20),
"quantity" INTEGER NOT NULL,
"status" VARCHAR(20) NOT NULL,
"installed" BOOLEAN NOT NULL DEFAULT false,
"start" TIMESTAMPTZ(3) NOT NULL,
"end" TIMESTAMPTZ(3),
"next_bill_at" TIMESTAMPTZ(3),
"canceled_at" TIMESTAMPTZ(3),
"trial_start" TIMESTAMPTZ(3),
"trial_end" TIMESTAMPTZ(3),
"created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ(3) NOT NULL,

CONSTRAINT "licenses_pkey" PRIMARY KEY ("key")
);

-- CreateTable
CREATE TABLE "installed_licenses" (
"key" VARCHAR NOT NULL,
"workspace_id" VARCHAR NOT NULL,
"installed_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"revalidated_at" TIMESTAMPTZ(3),

CONSTRAINT "installed_licenses_pkey" PRIMARY KEY ("key")
);
33 changes: 33 additions & 0 deletions packages/backend/server/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -562,3 +562,36 @@ model RuntimeConfig {
@@unique([module, key])
@@map("app_runtime_settings")
}

model License {
key String @id @map("key") @db.VarChar
// we won't ask user to sign up to buy a selfhost license, so we can't reference User model by userId here
email String @map("email") @db.VarChar
// stripe subscription id, null for one time payment
stripeSubscriptionId String? @map("stripe_subscription_id") @db.VarChar
recurring String @db.VarChar(20)
plan String @db.VarChar(20)
variant String? @db.VarChar(20)
quantity Int @db.Integer
status String @db.VarChar(20)
installed Boolean @default(false)
start DateTime @map("start") @db.Timestamptz(3)
end DateTime? @map("end") @db.Timestamptz(3)
nextBillAt DateTime? @map("next_bill_at") @db.Timestamptz(3)
canceledAt DateTime? @map("canceled_at") @db.Timestamptz(3)
trialStart DateTime? @map("trial_start") @db.Timestamptz(3)
trialEnd DateTime? @map("trial_end") @db.Timestamptz(3)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz(3)
@@map("licenses")
}

model InstalledLicense {
key String @id @map("key") @db.VarChar
workspaceId String @map("workspace_id") @db.VarChar
installedAt DateTime @default(now()) @map("installed_at") @db.Timestamptz(3)
revalidatedAt DateTime? @map("revalidated_at") @db.Timestamptz(3)
@@map("installed_licenses")
}

0 comments on commit 7003581

Please sign in to comment.