feat: dockerfile (node runtime), startup migration, README, runtime env config

This commit is contained in:
2026-06-10 08:16:45 +00:00
parent 56186a1fea
commit 7331fe75e8
12 changed files with 286 additions and 31 deletions

17
server/plugins/migrate.ts Normal file
View File

@@ -0,0 +1,17 @@
import { INIT_SQL } from "../utils/schema";
// Apply the schema idempotently on server startup. An advisory lock prevents concurrent
// instances from racing on CREATE TABLE. Idempotent CREATE ... IF NOT EXISTS means this is
// safe to run on every boot.
export default defineNitroPlugin(async () => {
try {
const sql = getSql();
await sql.begin(async (tx) => {
await tx`select pg_advisory_xact_lock(871042)`;
await tx.unsafe(INIT_SQL);
});
console.log("[migrate] schema ensured");
} catch (e) {
console.error("[migrate] failed:", (e as Error).message);
}
});