Add Paddle checkout foundation

This commit is contained in:
diyaa
2026-07-09 11:18:14 +02:00
parent ebdede8c79
commit db83d3612d
17 changed files with 1427 additions and 39 deletions
@@ -0,0 +1,45 @@
CREATE TABLE "billing_customers" (
"id" UUID NOT NULL,
"user_id" UUID NOT NULL,
"provider" "BillingProvider" NOT NULL,
"provider_customer_id" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3) NOT NULL,
CONSTRAINT "billing_customers_pkey" PRIMARY KEY ("id")
);
CREATE UNIQUE INDEX "billing_customers_user_id_key"
ON "billing_customers"("user_id");
CREATE UNIQUE INDEX "billing_customers_provider_customer_id_key"
ON "billing_customers"("provider_customer_id");
ALTER TABLE "billing_customers"
ADD CONSTRAINT "billing_customers_user_id_fkey"
FOREIGN KEY ("user_id") REFERENCES "users"("id")
ON DELETE CASCADE
ON UPDATE CASCADE;
INSERT INTO "billing_customers" (
"id",
"user_id",
"provider",
"provider_customer_id",
"created_at",
"updated_at"
)
SELECT
gen_random_uuid(),
"user_id",
"provider",
"provider_customer_id",
NOW(),
NOW()
FROM "user_subscriptions"
WHERE "provider_customer_id" IS NOT NULL
ON CONFLICT ("user_id") DO NOTHING;
DROP INDEX "user_subscriptions_provider_customer_id_key";
ALTER TABLE "user_subscriptions"
DROP COLUMN "provider_customer_id";
+13 -1
View File
@@ -34,6 +34,7 @@ model User {
incomingTransfers OwnershipTransfer[] @relation("OwnershipTransferToUser")
initiatedTransfers OwnershipTransfer[] @relation("OwnershipTransferRequestedByUser")
accountSessions AccountSession[]
billingCustomer BillingCustomer?
subscription UserSubscription?
entitlements UserEntitlement[]
@@ -304,11 +305,22 @@ model AccountSession {
@@map("account_sessions")
}
model BillingCustomer {
id String @id @default(uuid()) @db.Uuid
userId String @unique @map("user_id") @db.Uuid
provider BillingProvider
providerCustomerId String @unique @map("provider_customer_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
@@map("billing_customers")
}
model UserSubscription {
id String @id @default(uuid()) @db.Uuid
userId String @unique @map("user_id") @db.Uuid
provider BillingProvider
providerCustomerId String? @unique @map("provider_customer_id")
providerSubscriptionId String? @unique @map("provider_subscription_id")
plan SubscriptionPlan
status SubscriptionStatus