fix: stop drift migration from dropping tracking table

This commit is contained in:
mahmood
2026-09-15 22:40:00 +03:30
parent 1f734bedca
commit 2448627e1b
142 changed files with 221 additions and 1103 deletions
+10 -1
View File
@@ -185,7 +185,16 @@ export async function runMigrations(prisma: PrismaClient): Promise<MigrationResu
const legacyName = LEGACY_NAME_ALIASES[file.name];
if (appliedNames.has(file.name) || (legacyName && appliedNames.has(legacyName))) continue;
const statements = splitSqlStatements(readFileSync(file.path, 'utf8'));
const statements = splitSqlStatements(readFileSync(file.path, 'utf8')).filter(
(statement) => {
// Prisma migrate diff once emitted DROP TABLE "_goldbank_migrations"
// because that tracking table exists in the live DB but not in schema.
// Never allow a migration to destroy our own bookkeeping.
const normalized = statement.replace(/\s+/g, ' ').trim().toLowerCase();
return !normalized.startsWith(`drop table "${TRACKING_TABLE.toLowerCase()}"`)
&& !normalized.startsWith(`drop table ${TRACKING_TABLE.toLowerCase()}`);
},
);
await prisma.$transaction(
async (tx) => {
for (const statement of statements) {