From c66bf68373c5b0fbf2d5ac4eeea7d5e9a0eb5efe Mon Sep 17 00:00:00 2001 From: ginnoir Date: Wed, 6 May 2026 20:49:20 -0500 Subject: [PATCH] Seed household on container startup via seed.mjs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- Dockerfile | 1 + docker-entrypoint.sh | 2 ++ scripts/seed.mjs | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 scripts/seed.mjs diff --git a/Dockerfile b/Dockerfile index 2583815..3a534ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,6 +38,7 @@ COPY --from=builder --chown=nextjs:nodejs /app/public ./public # the app itself imports, not the postgres-js/migrator subpath. COPY --from=builder --chown=nextjs:nodejs /app/drizzle ./drizzle COPY --from=builder --chown=nextjs:nodejs /app/scripts/migrate.mjs ./scripts/migrate.mjs +COPY --from=builder --chown=nextjs:nodejs /app/scripts/seed.mjs ./scripts/seed.mjs COPY --from=builder --chown=nextjs:nodejs /app/node_modules/drizzle-orm ./node_modules/drizzle-orm COPY --from=builder --chown=nextjs:nodejs /app/node_modules/postgres ./node_modules/postgres COPY --chown=nextjs:nodejs docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index a9d63d0..13400ef 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -8,4 +8,6 @@ else echo "skipping migrations (RUN_MIGRATIONS=$RUN_MIGRATIONS)" fi +node /app/scripts/seed.mjs + exec node /app/server.js diff --git a/scripts/seed.mjs b/scripts/seed.mjs new file mode 100644 index 0000000..e6e3907 --- /dev/null +++ b/scripts/seed.mjs @@ -0,0 +1,24 @@ +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 }); +}