Skip to content

Commit

Permalink
Add DB migration
Browse files Browse the repository at this point in the history
  • Loading branch information
paustint committed Jan 20, 2025
1 parent 50225a4 commit 031465e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 46 additions & 0 deletions prisma/migrations/20250120005857_billing/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
-- AlterTable
ALTER TABLE "entitlement" ADD COLUMN "googleDrive" BOOLEAN NOT NULL DEFAULT false;

-- CreateTable
CREATE TABLE "billing_account" (
"userId" UUID NOT NULL,
"customerId" TEXT NOT NULL,
"createdAt" TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL
);

-- CreateTable
CREATE TABLE "subscription" (
"id" UUID NOT NULL DEFAULT uuid_generate_v4(),
"userId" UUID NOT NULL,
"customerId" TEXT NOT NULL,
"productId" UUID,
"subscriptionId" TEXT NOT NULL,
"priceId" TEXT NOT NULL,
"status" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

CONSTRAINT "subscription_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "billing_account_userId_key" ON "billing_account"("userId");

-- CreateIndex
CREATE UNIQUE INDEX "billing_account_customerId_key" ON "billing_account"("customerId");

-- CreateIndex
CREATE UNIQUE INDEX "unique_customer" ON "billing_account"("userId", "customerId");

-- CreateIndex
CREATE UNIQUE INDEX "unique_subscription" ON "subscription"("userId", "subscriptionId", "priceId");

-- AddForeignKey
ALTER TABLE "billing_account" ADD CONSTRAINT "billing_account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "subscription" ADD CONSTRAINT "subscription_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "subscription" ADD CONSTRAINT "subscription_customerId_fkey" FOREIGN KEY ("customerId") REFERENCES "billing_account"("customerId") ON DELETE CASCADE ON UPDATE CASCADE;
2 changes: 1 addition & 1 deletion prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
# It should be added in your version-control system (e.g., Git)
provider = "postgresql"

0 comments on commit 031465e

Please sign in to comment.