mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-23 19:27:25 +02:00
✨ Add licensing api (#1723)
This commit is contained in:
parent
982fc39ac7
commit
679d6fb034
14 changed files with 607 additions and 40 deletions
|
@ -0,0 +1,59 @@
|
|||
-- CreateEnum
|
||||
CREATE TYPE "LicenseType" AS ENUM ('PLUS', 'ORGANIZATION', 'ENTERPRISE');
|
||||
|
||||
-- CreateEnum
|
||||
CREATE TYPE "LicenseStatus" AS ENUM ('ACTIVE', 'REVOKED');
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "licenses" (
|
||||
"id" TEXT NOT NULL,
|
||||
"license_key" TEXT NOT NULL,
|
||||
"version" INTEGER,
|
||||
"type" "LicenseType" NOT NULL,
|
||||
"seats" INTEGER,
|
||||
"issued_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"expires_at" TIMESTAMP(3),
|
||||
"licensee_email" TEXT,
|
||||
"licensee_name" TEXT,
|
||||
"status" "LicenseStatus" NOT NULL DEFAULT 'ACTIVE',
|
||||
"stripe_customer_id" TEXT,
|
||||
|
||||
CONSTRAINT "licenses_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "license_validations" (
|
||||
"id" TEXT NOT NULL,
|
||||
"license_id" TEXT NOT NULL,
|
||||
"ip_address" TEXT,
|
||||
"fingerprint" TEXT,
|
||||
"validated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"user_agent" TEXT,
|
||||
|
||||
CONSTRAINT "license_validations_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "instance_licenses" (
|
||||
"id" TEXT NOT NULL,
|
||||
"license_key" TEXT NOT NULL,
|
||||
"version" INTEGER,
|
||||
"type" "LicenseType" NOT NULL,
|
||||
"seats" INTEGER,
|
||||
"issued_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"expires_at" TIMESTAMP(3),
|
||||
"licensee_email" TEXT,
|
||||
"licensee_name" TEXT,
|
||||
"status" "LicenseStatus" NOT NULL DEFAULT 'ACTIVE',
|
||||
|
||||
CONSTRAINT "instance_licenses_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "licenses_license_key_key" ON "licenses"("license_key");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "instance_licenses_license_key_key" ON "instance_licenses"("license_key");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "license_validations" ADD CONSTRAINT "license_validations_license_id_fkey" FOREIGN KEY ("license_id") REFERENCES "licenses"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
56
packages/database/prisma/models/licensing.prisma
Normal file
56
packages/database/prisma/models/licensing.prisma
Normal file
|
@ -0,0 +1,56 @@
|
|||
enum LicenseType {
|
||||
PLUS
|
||||
ORGANIZATION
|
||||
ENTERPRISE
|
||||
}
|
||||
|
||||
enum LicenseStatus {
|
||||
ACTIVE
|
||||
REVOKED
|
||||
}
|
||||
|
||||
model License {
|
||||
id String @id @default(cuid())
|
||||
licenseKey String @unique @map("license_key")
|
||||
version Int? @map("version")
|
||||
type LicenseType
|
||||
seats Int? @map("seats")
|
||||
issuedAt DateTime @default(now()) @map("issued_at")
|
||||
expiresAt DateTime? @map("expires_at")
|
||||
licenseeEmail String? @map("licensee_email")
|
||||
licenseeName String? @map("licensee_name")
|
||||
status LicenseStatus @default(ACTIVE) @map("status")
|
||||
stripeCustomerId String? @map("stripe_customer_id")
|
||||
|
||||
validations LicenseValidation[]
|
||||
|
||||
@@map("licenses")
|
||||
}
|
||||
|
||||
model LicenseValidation {
|
||||
id String @id @default(cuid())
|
||||
licenseId String @map("license_id")
|
||||
license License @relation(fields: [licenseId], references: [id], onDelete: Cascade)
|
||||
ipAddress String? @map("ip_address")
|
||||
fingerprint String? @map("fingerprint")
|
||||
validatedAt DateTime @default(now()) @map("validated_at")
|
||||
userAgent String? @map("user_agent")
|
||||
|
||||
@@map("license_validations")
|
||||
}
|
||||
|
||||
|
||||
model InstanceLicense {
|
||||
id String @id @default(cuid())
|
||||
licenseKey String @unique @map("license_key")
|
||||
version Int? @map("version")
|
||||
type LicenseType
|
||||
seats Int? @map("seats")
|
||||
issuedAt DateTime @default(now()) @map("issued_at")
|
||||
expiresAt DateTime? @map("expires_at")
|
||||
licenseeEmail String? @map("licensee_email")
|
||||
licenseeName String? @map("licensee_name")
|
||||
status LicenseStatus @default(ACTIVE) @map("status")
|
||||
|
||||
@@map("instance_licenses")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue