Files
ginnoirandClaude Sonnet 4.6 c66bf68373 Seed household on container startup via seed.mjs
Without a household row the signIn callback has nothing to attach the
first user to, causing "No household membership" on first load. Add
scripts/seed.mjs (plain ESM, only needs postgres which is already in the
image) and run it from the entrypoint after migrations. Idempotent — skips
if a household already exists. Default calendars/lists are created by the
signIn callback when the first user authenticates.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 20:49:20 -05:00

25 lines
759 B
JavaScript

import postgres from "postgres";
const url = process.env.DATABASE_URL;
if (!url) {
console.error(JSON.stringify({ level: "error", msg: "DATABASE_URL is required" }));
process.exit(1);
}
const sql = postgres(url, { max: 1 });
try {
const [existing] = await sql`SELECT id, name FROM households LIMIT 1`;
if (existing) {
console.log(JSON.stringify({ level: "info", msg: "household exists", name: existing.name }));
} else {
await sql`INSERT INTO households (name) VALUES ('Home')`;
console.log(JSON.stringify({ level: "info", msg: "seeded household Home" }));
}
} catch (err) {
console.error(JSON.stringify({ level: "error", msg: "seed failed", err: String(err) }));
process.exit(1);
} finally {
await sql.end({ timeout: 5 });
}