-- CreateTable CREATE TABLE "plugin_subscriptions" ( "id" TEXT NOT NULL PRIMARY KEY, "tenant_id" TEXT NOT NULL, "name" TEXT NOT NULL, "specs" TEXT, "price_rials" INTEGER, "charged_at" DATETIME, "plan_months" INTEGER, "expires_at" DATETIME, "description" TEXT, "alert_days_before" INTEGER NOT NULL DEFAULT 3, "last_alert_date" DATETIME, "is_active" BOOLEAN NOT NULL DEFAULT true, "created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, "updated_at" DATETIME NOT NULL, CONSTRAINT "plugin_subscriptions_tenant_id_fkey" FOREIGN KEY ("tenant_id") REFERENCES "tenants" ("id") ON DELETE CASCADE ON UPDATE CASCADE ); -- CreateTable CREATE TABLE "plugin_charges" ( "id" TEXT NOT NULL PRIMARY KEY, "plugin_id" TEXT NOT NULL, "charged_at" DATETIME NOT NULL, "plan_months" INTEGER NOT NULL, "price_rials" INTEGER NOT NULL, "expires_at" DATETIME NOT NULL, "note" TEXT, "created_by_id" TEXT, "created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT "plugin_charges_plugin_id_fkey" FOREIGN KEY ("plugin_id") REFERENCES "plugin_subscriptions" ("id") ON DELETE CASCADE ON UPDATE CASCADE ); -- CreateIndex CREATE INDEX "plugin_subscriptions_tenant_id_idx" ON "plugin_subscriptions"("tenant_id"); -- CreateIndex CREATE INDEX "plugin_subscriptions_expires_at_idx" ON "plugin_subscriptions"("expires_at"); -- CreateIndex CREATE INDEX "plugin_subscriptions_is_active_idx" ON "plugin_subscriptions"("is_active"); -- CreateIndex CREATE INDEX "plugin_charges_plugin_id_idx" ON "plugin_charges"("plugin_id"); -- CreateIndex CREATE INDEX "plugin_charges_created_at_idx" ON "plugin_charges"("created_at");