46 lines
2.1 KiB
SQL
46 lines
2.1 KiB
SQL
-- 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;
|