integrate backend with paddle

This commit is contained in:
m5r
2021-09-27 06:08:02 +08:00
parent 9cec49f255
commit 0f2c3daf77
16 changed files with 679 additions and 25 deletions

View File

@ -0,0 +1,41 @@
/*
Warnings:
- You are about to drop the column `paddleCustomerId` on the `Organization` table. All the data in the column will be lost.
- You are about to drop the column `paddleSubscriptionId` on the `Organization` table. All the data in the column will be lost.
*/
-- CreateEnum
CREATE TYPE "SubscriptionStatus" AS ENUM ('active', 'trialing', 'past_due', 'paused', 'deleted');
-- AlterTable
ALTER TABLE "Organization" DROP COLUMN "paddleCustomerId",
DROP COLUMN "paddleSubscriptionId";
-- CreateTable
CREATE TABLE "Subscription" (
"createdAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMPTZ NOT NULL,
"paddleSubscriptionId" TEXT NOT NULL,
"paddlePlanId" TEXT NOT NULL,
"paddleCheckoutId" TEXT NOT NULL,
"status" "SubscriptionStatus" NOT NULL,
"updateUrl" TEXT NOT NULL,
"cancelUrl" TEXT NOT NULL,
"currency" TEXT NOT NULL,
"unitPrice" TEXT NOT NULL,
"nextBillDate" DATE NOT NULL,
"lastEventTime" TIMESTAMP NOT NULL,
"organizationId" TEXT,
CONSTRAINT "Subscription_pkey" PRIMARY KEY ("paddleSubscriptionId")
);
-- CreateIndex
CREATE UNIQUE INDEX "Subscription_paddleSubscriptionId_key" ON "Subscription"("paddleSubscriptionId");
-- CreateIndex
CREATE UNIQUE INDEX "Subscription_organizationId_unique" ON "Subscription"("organizationId");
-- AddForeignKey
ALTER TABLE "Subscription" ADD CONSTRAINT "Subscription_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@ -13,12 +13,10 @@ generator client {
// --------------------------------------
model Organization {
id String @id @default(uuid())
createdAt DateTime @default(now()) @db.Timestamptz
updatedAt DateTime @updatedAt @db.Timestamptz
encryptionKey String
paddleCustomerId String?
paddleSubscriptionId String?
id String @id @default(uuid())
createdAt DateTime @default(now()) @db.Timestamptz
updatedAt DateTime @updatedAt @db.Timestamptz
encryptionKey String
twilioAccountSid String?
twilioAuthToken String? // TODO: encrypt it with encryptionKey
@ -32,10 +30,38 @@ model Organization {
messages Message[]
phoneCalls PhoneCall[]
processingPhoneNumbers ProcessingPhoneNumber[]
subscription Subscription?
@@unique([id, twilioAccountSid])
}
model Subscription {
createdAt DateTime @default(now()) @db.Timestamptz
updatedAt DateTime @updatedAt @db.Timestamptz
paddleSubscriptionId String @id @unique
paddlePlanId String
paddleCheckoutId String
status SubscriptionStatus
updateUrl String
cancelUrl String
currency String
unitPrice String
nextBillDate DateTime @db.Date
lastEventTime DateTime @db.Timestamp
organization Organization? @relation(fields: [organizationId], references: [id], onDelete: Cascade)
organizationId String?
}
enum SubscriptionStatus {
active
trialing
past_due
paused
deleted
}
model Membership {
id String @id @default(uuid())
role MembershipRole