fix pluggin bug
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
-- Plugin store tables were added to schema.prisma without a CREATE TABLE
|
||||
-- migration (publisher likely used db push, or never created them at all).
|
||||
-- Replica ALTER of images/receipt_url then fails. IF NOT EXISTS is safe
|
||||
-- on publisher if tables already exist.
|
||||
|
||||
DO $$ BEGIN
|
||||
CREATE TYPE "PluginPurchaseStatus" AS ENUM ('pending', 'approved', 'rejected', 'cancelled');
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN NULL;
|
||||
END $$;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "plugin_catalog_items" (
|
||||
"id" TEXT NOT NULL,
|
||||
"setting_key" VARCHAR(50) NOT NULL,
|
||||
"title_fa" TEXT NOT NULL,
|
||||
"description" TEXT,
|
||||
"images" JSONB,
|
||||
"in_store" BOOLEAN NOT NULL DEFAULT true,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
CONSTRAINT "plugin_catalog_items_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "plugin_catalog_items_setting_key_key"
|
||||
ON "plugin_catalog_items"("setting_key");
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "plugin_catalog_prices" (
|
||||
"id" TEXT NOT NULL,
|
||||
"catalog_item_id" TEXT NOT NULL,
|
||||
"duration_days" INTEGER NOT NULL,
|
||||
"enabled" BOOLEAN NOT NULL DEFAULT false,
|
||||
"original_price_rials" INTEGER NOT NULL DEFAULT 0,
|
||||
"final_price_rials" INTEGER NOT NULL DEFAULT 0,
|
||||
CONSTRAINT "plugin_catalog_prices_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "plugin_catalog_prices_catalog_item_id_duration_days_key"
|
||||
ON "plugin_catalog_prices"("catalog_item_id", "duration_days");
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "plugin_purchase_requests" (
|
||||
"id" TEXT NOT NULL,
|
||||
"tenant_id" TEXT NOT NULL,
|
||||
"catalog_item_id" TEXT NOT NULL,
|
||||
"duration_days" INTEGER NOT NULL,
|
||||
"original_price_rials" INTEGER NOT NULL,
|
||||
"final_price_rials" INTEGER NOT NULL,
|
||||
"status" "PluginPurchaseStatus" NOT NULL DEFAULT 'pending',
|
||||
"auto_cut_on_expiry" BOOLEAN,
|
||||
"plugin_subscription_id" TEXT,
|
||||
"receipt_url" TEXT,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
"decided_at" TIMESTAMP(3),
|
||||
CONSTRAINT "plugin_purchase_requests_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "plugin_purchase_requests_tenant_id_status_idx"
|
||||
ON "plugin_purchase_requests"("tenant_id", "status");
|
||||
CREATE INDEX IF NOT EXISTS "plugin_purchase_requests_catalog_item_id_idx"
|
||||
ON "plugin_purchase_requests"("catalog_item_id");
|
||||
CREATE INDEX IF NOT EXISTS "plugin_purchase_requests_created_at_idx"
|
||||
ON "plugin_purchase_requests"("created_at");
|
||||
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "plugin_catalog_prices"
|
||||
ADD CONSTRAINT "plugin_catalog_prices_catalog_item_id_fkey"
|
||||
FOREIGN KEY ("catalog_item_id") REFERENCES "plugin_catalog_items"("id")
|
||||
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN NULL;
|
||||
END $$;
|
||||
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "plugin_purchase_requests"
|
||||
ADD CONSTRAINT "plugin_purchase_requests_tenant_id_fkey"
|
||||
FOREIGN KEY ("tenant_id") REFERENCES "tenants"("id")
|
||||
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN NULL;
|
||||
END $$;
|
||||
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "plugin_purchase_requests"
|
||||
ADD CONSTRAINT "plugin_purchase_requests_catalog_item_id_fkey"
|
||||
FOREIGN KEY ("catalog_item_id") REFERENCES "plugin_catalog_items"("id")
|
||||
ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN NULL;
|
||||
END $$;
|
||||
Reference in New Issue
Block a user