chore(server): auto roll back failed migrations (#12697)

This commit is contained in:
fengmk2
2025-06-04 14:45:42 +08:00
committed by GitHub
parent 1f0cc51462
commit f54bc0c047

View File

@@ -47,5 +47,33 @@ function runPredeployScript() {
});
}
function fixFailedMigrations() {
console.log('fixing failed migrations.');
const maybeFailedMigrations = [
'20250521083048_fix_workspace_embedding_chunk_primary_key',
];
for (const migration of maybeFailedMigrations) {
try {
execSync(`yarn prisma migrate resolve --rolled-back ${migration}`, {
encoding: 'utf-8',
env: process.env,
stdio: 'pipe',
});
console.log(`migration [${migration}] has been rolled back.`);
} catch (err) {
if (
err.message.includes(
'cannot be rolled back because it is not in a failed state'
)
) {
// migration has been rolled back, skip it
continue;
}
throw err;
}
}
}
prepare();
fixFailedMigrations();
runPredeployScript();