fix: stop drift migration from dropping tracking table
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user