Add support subscription panel API with optional free periods.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
-- Support / maintenance subscriptions (0..N per tenant), with optional free periods.
|
||||
CREATE TABLE "public"."support_subscriptions" (
|
||||
"id" TEXT NOT NULL,
|
||||
"tenant_id" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"specs" TEXT,
|
||||
"price_rials" INTEGER,
|
||||
"is_free" BOOLEAN NOT NULL DEFAULT false,
|
||||
"charged_at" TIMESTAMP(3),
|
||||
"plan_months" INTEGER,
|
||||
"expires_at" TIMESTAMP(3),
|
||||
"description" TEXT,
|
||||
"alert_days_before" INTEGER NOT NULL DEFAULT 3,
|
||||
"last_alert_date" TIMESTAMP(3),
|
||||
"is_active" BOOLEAN NOT NULL DEFAULT true,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "support_subscriptions_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE TABLE "public"."support_charges" (
|
||||
"id" TEXT NOT NULL,
|
||||
"support_id" TEXT NOT NULL,
|
||||
"charged_at" TIMESTAMP(3) NOT NULL,
|
||||
"plan_months" INTEGER NOT NULL,
|
||||
"price_rials" INTEGER NOT NULL,
|
||||
"is_free" BOOLEAN NOT NULL DEFAULT false,
|
||||
"expires_at" TIMESTAMP(3) NOT NULL,
|
||||
"note" TEXT,
|
||||
"created_by_id" TEXT,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "support_charges_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE INDEX "support_subscriptions_tenant_id_idx" ON "public"."support_subscriptions"("tenant_id");
|
||||
CREATE INDEX "support_subscriptions_expires_at_idx" ON "public"."support_subscriptions"("expires_at");
|
||||
CREATE INDEX "support_subscriptions_is_active_idx" ON "public"."support_subscriptions"("is_active");
|
||||
CREATE INDEX "support_subscriptions_is_free_idx" ON "public"."support_subscriptions"("is_free");
|
||||
CREATE INDEX "support_charges_support_id_idx" ON "public"."support_charges"("support_id");
|
||||
CREATE INDEX "support_charges_created_at_idx" ON "public"."support_charges"("created_at");
|
||||
|
||||
ALTER TABLE "public"."support_subscriptions" ADD CONSTRAINT "support_subscriptions_tenant_id_fkey" FOREIGN KEY ("tenant_id") REFERENCES "public"."tenants"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
ALTER TABLE "public"."support_charges" ADD CONSTRAINT "support_charges_support_id_fkey" FOREIGN KEY ("support_id") REFERENCES "public"."support_subscriptions"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -74,6 +74,7 @@ model Tenant {
|
||||
/// 0..N hosting/billing servers per sold version (not the same as nodeServer API URL)
|
||||
serverAccounts ServerAccount[]
|
||||
pluginSubscriptions PluginSubscription[]
|
||||
supportSubscriptions SupportSubscription[]
|
||||
|
||||
@@index([product])
|
||||
@@index([isActive])
|
||||
@@ -279,3 +280,53 @@ model PluginCharge {
|
||||
@@index([createdAt])
|
||||
@@map("plugin_charges")
|
||||
}
|
||||
|
||||
/// Support/maintenance subscription for a sold version (0..N per tenant).
|
||||
/// Can be free (isFree) for 1|3|6|12 months gift periods.
|
||||
model SupportSubscription {
|
||||
id String @id @default(cuid())
|
||||
tenantId String @map("tenant_id")
|
||||
name String
|
||||
specs String?
|
||||
priceRials Int? @map("price_rials")
|
||||
/// When true, current period is complimentary (price should be 0)
|
||||
isFree Boolean @default(false) @map("is_free")
|
||||
chargedAt DateTime? @map("charged_at")
|
||||
/// Plan length in months: 1 | 3 | 6 | 12
|
||||
planMonths Int? @map("plan_months")
|
||||
expiresAt DateTime? @map("expires_at")
|
||||
description String?
|
||||
alertDaysBefore Int @default(3) @map("alert_days_before")
|
||||
lastAlertDate DateTime? @map("last_alert_date")
|
||||
isActive Boolean @default(true) @map("is_active")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
||||
charges SupportCharge[]
|
||||
|
||||
@@index([tenantId])
|
||||
@@index([expiresAt])
|
||||
@@index([isActive])
|
||||
@@index([isFree])
|
||||
@@map("support_subscriptions")
|
||||
}
|
||||
|
||||
model SupportCharge {
|
||||
id String @id @default(cuid())
|
||||
supportId String @map("support_id")
|
||||
chargedAt DateTime @map("charged_at")
|
||||
planMonths Int @map("plan_months")
|
||||
priceRials Int @map("price_rials")
|
||||
isFree Boolean @default(false) @map("is_free")
|
||||
expiresAt DateTime @map("expires_at")
|
||||
note String?
|
||||
createdById String? @map("created_by_id")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
|
||||
support SupportSubscription @relation(fields: [supportId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([supportId])
|
||||
@@index([createdAt])
|
||||
@@map("support_charges")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user