fix(api): survive existing-schema boots without DB shell

Nginx 502 Host-not-found meant the API never stayed listening. Stamp all
migrations when tracking is empty but a late table exists, apply DDL
statement-by-statement skipping already-exists, harden remaining CREATE
TYPE/TABLE files, and never let seed crash the process.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
mahmood
2026-10-27 17:35:25 +03:30
co-authored by Cursor
parent b05b6515f2
commit 15adbb7fe1
11 changed files with 202 additions and 169 deletions
+12 -5
View File
@@ -52,11 +52,18 @@ export async function prepareDatabase(): Promise<void> {
return;
}
const seeded = await runOnce(prisma, 'seed:initial', async () => {
const { stdout } = await execFileAsync(process.execPath, [seedScript]);
if (stdout.trim()) logger.log(stdout.trim());
});
if (seeded) logger.log('Seed data inserted');
try {
const seeded = await runOnce(prisma, 'seed:initial', async () => {
const { stdout } = await execFileAsync(process.execPath, [seedScript]);
if (stdout.trim()) logger.log(stdout.trim());
});
if (seeded) logger.log('Seed data inserted');
} catch (err) {
// Seed must never crash-loop the API (nginx Host not found / 502).
logger.warn(
`Seed skipped after error: ${err instanceof Error ? err.message : String(err)}`,
);
}
} finally {
await prisma.$disconnect();
}