Keep legacy subscription tables as unmanaged instead of dropping them
This commit is contained in:
@@ -5,6 +5,15 @@ import { defineConfig } from 'prisma/config';
|
||||
|
||||
export default defineConfig({
|
||||
schema: 'prisma/schema.prisma',
|
||||
// Legacy subscription tables are retained in the database but are no longer
|
||||
// managed by Prisma Migrate. They must never be dropped (production may not
|
||||
// own them and the data is kept for recovery).
|
||||
experimental: {
|
||||
externalTables: true
|
||||
},
|
||||
tables: {
|
||||
external: ['public.SubscriptionLevel', 'public.ProclamationCategorySubscriptionLevel']
|
||||
},
|
||||
migrations: {
|
||||
path: 'prisma/migrations',
|
||||
seed: 'tsx prisma/seed.ts'
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
-- Retain the legacy subscription artifacts as externally managed data.
|
||||
--
|
||||
-- SubscriptionLevel and ProclamationCategorySubscriptionLevel are no longer
|
||||
-- modeled by the application. They are declared as external tables in
|
||||
-- prisma.config.ts so Prisma Migrate ignores them entirely and never drops
|
||||
-- them (production may not own these tables, and their data is kept for
|
||||
-- recovery).
|
||||
--
|
||||
-- This migration only touches Prisma-managed tables to decouple them from the
|
||||
-- legacy FK. It is intentionally idempotent so it applies cleanly to
|
||||
-- production (columns present, NOT NULL, FK present), a fresh database built
|
||||
-- from migration history, and development databases that already removed the
|
||||
-- legacy objects.
|
||||
|
||||
-- Ensure the legacy columns exist. On databases built from migration history
|
||||
-- these already exist; this re-adds them on environments that dropped them.
|
||||
ALTER TABLE "Proclamation" ADD COLUMN IF NOT EXISTS "subscriptionLevelId" INTEGER;
|
||||
ALTER TABLE "LicenseKey" ADD COLUMN IF NOT EXISTS "level" TEXT;
|
||||
|
||||
-- Decouple from SubscriptionLevel: drop the FK and relax NOT NULL so the
|
||||
-- application can keep inserting rows without a legacy subscription value.
|
||||
ALTER TABLE "Proclamation" DROP CONSTRAINT IF EXISTS "Proclamation_subscriptionLevelId_fkey";
|
||||
ALTER TABLE "Proclamation" ALTER COLUMN "subscriptionLevelId" DROP NOT NULL;
|
||||
ALTER TABLE "LicenseKey" ALTER COLUMN "level" DROP NOT NULL;
|
||||
@@ -130,6 +130,9 @@ model Proclamation {
|
||||
groupId Int
|
||||
group ProclamationGroup @relation(fields: [groupId], references: [id])
|
||||
userProclamations UserProclamations[]
|
||||
// Legacy subscription-level FK. Retained in the database but unmanaged; the
|
||||
// FK constraint is dropped and the value is left NULL. Hidden from the client.
|
||||
subscriptionLevelId Int? @ignore
|
||||
}
|
||||
|
||||
model ProclamationGroup {
|
||||
@@ -198,6 +201,9 @@ model LicenseKey {
|
||||
userId String?
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
|
||||
email String?
|
||||
// Legacy subscription level. Retained in the database but unmanaged; hidden
|
||||
// from the client and left NULL.
|
||||
level String? @ignore
|
||||
|
||||
@@index([userId])
|
||||
@@index([email])
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user