- scripts/seed.ts: idempotent pnpm db:seed inserts "Home" household if none exists (powered by tsx)
- signIn callback: first member of household gets owner role, subsequent users get member
- src/lib/session.ts: getCurrentSession() returns { user, household, role }, throws if unauthenticated or unmembered
- /settings/household: member list for all roles; rename form gated to owner only (server action also enforces)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
23 lines
619 B
TypeScript
23 lines
619 B
TypeScript
import postgres from "postgres";
|
|
import { drizzle } from "drizzle-orm/postgres-js";
|
|
import { households } from "@/modules/_core/schema";
|
|
|
|
const client = postgres(process.env["DATABASE_URL"]!);
|
|
const db = drizzle(client);
|
|
|
|
async function seed() {
|
|
const [existing] = await db.select().from(households).limit(1);
|
|
if (existing) {
|
|
console.log(`Household already exists ("${existing.name}"), skipping.`);
|
|
} else {
|
|
await db.insert(households).values({ name: "Home" });
|
|
console.log('Seeded household "Home".');
|
|
}
|
|
await client.end();
|
|
}
|
|
|
|
seed().catch((err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|