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>
25 lines
759 B
JavaScript
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 });
|
|
}
|