Files
2024-06-11 11:58:50 +05:30

78 lines
2.2 KiB
SQL

-- CreateEnum
CREATE TYPE "PricingType" AS ENUM ('one_time', 'recurring');
-- CreateEnum
CREATE TYPE "PricingPlanInterval" AS ENUM ('day', 'week', 'month', 'year');
-- CreateEnum
CREATE TYPE "SubscriptionStatus" AS ENUM ('trialing', 'active', 'canceled', 'incomplete', 'incomplete_expired', 'past_due', 'unpaid', 'paused');
-- CreateTable
CREATE TABLE "BillingProduct" (
"id" TEXT NOT NULL,
"active" BOOLEAN NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT,
"metadata" JSONB,
CONSTRAINT "BillingProduct_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "BillingPrice" (
"id" TEXT NOT NULL,
"productId" TEXT NOT NULL,
"active" BOOLEAN NOT NULL,
"description" TEXT,
"unitAmount" BIGINT,
"currency" CHAR(3) NOT NULL,
"type" "PricingType" NOT NULL,
"interval" "PricingPlanInterval",
"intervalCount" INTEGER,
"trialPeriodDays" INTEGER,
"metadata" JSONB,
CONSTRAINT "BillingPrice_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "BillingSubscription" (
"id" TEXT NOT NULL,
"priceId" TEXT NOT NULL,
"quantity" INTEGER NOT NULL,
"status" "SubscriptionStatus" NOT NULL,
"cancelAtPeriodEnd" BOOLEAN NOT NULL,
"created" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"currentPeriodStart" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"currentPeriodEnd" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"endedAt" TIMESTAMP(3),
"cancelAt" TIMESTAMP(3),
"canceledAt" TIMESTAMP(3),
"trialStart" TIMESTAMP(3),
"trialEnd" TIMESTAMP(3),
"metadata" JSONB,
"customerId" TEXT NOT NULL,
CONSTRAINT "BillingSubscription_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "BillingCustomer" (
"id" TEXT NOT NULL,
"companyId" TEXT,
CONSTRAINT "BillingCustomer_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "BillingPrice_productId_idx" ON "BillingPrice"("productId");
-- CreateIndex
CREATE INDEX "BillingSubscription_priceId_idx" ON "BillingSubscription"("priceId");
-- CreateIndex
CREATE INDEX "BillingSubscription_customerId_idx" ON "BillingSubscription"("customerId");
-- CreateIndex
CREATE INDEX "BillingCustomer_companyId_idx" ON "BillingCustomer"("companyId");