Keep legacy subscription tables as unmanaged instead of dropping them

This commit is contained in:
NeilClack
2026-09-10 11:48:49 -05:00
parent d89fc6837c
commit 4a1777de87
4 changed files with 40 additions and 1 deletions
+9
View File
@@ -5,6 +5,15 @@ import { defineConfig } from 'prisma/config';
export default defineConfig({ export default defineConfig({
schema: 'prisma/schema.prisma', 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: { migrations: {
path: 'prisma/migrations', path: 'prisma/migrations',
seed: 'tsx prisma/seed.ts' 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;
+6
View File
@@ -130,6 +130,9 @@ model Proclamation {
groupId Int groupId Int
group ProclamationGroup @relation(fields: [groupId], references: [id]) group ProclamationGroup @relation(fields: [groupId], references: [id])
userProclamations UserProclamations[] 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 { model ProclamationGroup {
@@ -198,6 +201,9 @@ model LicenseKey {
userId String? userId String?
user User? @relation(fields: [userId], references: [id], onDelete: SetNull) user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
email String? email String?
// Legacy subscription level. Retained in the database but unmanaged; hidden
// from the client and left NULL.
level String? @ignore
@@index([userId]) @@index([userId])
@@index([email]) @@index([email])
File diff suppressed because one or more lines are too long