integrate backend with paddle
This commit is contained in:
41
db/migrations/20210926210806_add_subscription/migration.sql
Normal file
41
db/migrations/20210926210806_add_subscription/migration.sql
Normal 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;
|
@ -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
|
||||
|
Reference in New Issue
Block a user