Files
Bonna-Moon-Studio/app/scripts/seed-owner.mjs
Bonna c4ba1591c7 app/: production port — Postgres + Prisma + OTM-account auth (v0.2.0)
Prototype stays untouched (Bonna's laptop daily driver until cutover).
app/ is the deployable bms-backbone: same routes/frontend, Prisma models
replacing node:sqlite, session-cookie login backed by a User table seeded
via the platform SEED_OWNER_* convention (bcryptjs), /api/health with
APP_VERSION, photos/files under DATA_DIR (/app/data uploads mount),
Dockerfile + entrypoint (prisma db push + owner seed + serve), and a
one-shot sqlite→postgres migration script for Bonna's existing data.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-06 22:10:55 -05:00

19 lines
775 B
JavaScript

// OTM owner seed — runs at container start. Creates the owner ONLY when
// SEED_OWNER_EMAIL/SEED_OWNER_PASSWORD_HASH are set AND the User table is
// empty (the platform convention — see platform CLAUDE.md "Owner seed").
import { PrismaClient } from "@prisma/client";
const db = new PrismaClient();
const email = process.env.SEED_OWNER_EMAIL?.toLowerCase().trim();
const hash = process.env.SEED_OWNER_PASSWORD_HASH;
if (!email || !hash) {
console.log("seed-owner: SEED_OWNER_* not set — skipping");
} else if ((await db.user.count()) > 0) {
console.log("seed-owner: users exist — skipping");
} else {
await db.user.create({ data: { email, passwordHash: hash, role: "OWNER" } });
console.log(`seed-owner: created OWNER ${email}`);
}
await db.$disconnect();