← back to Nineoh Guide
db/seed.mjs
43 lines
// Seeds the canonical `shows` row with ORIGINAL descriptive copy + the app-level
// unofficial disclaimer. Idempotent. Run: node db/seed.mjs
import pg from "pg";
const DATABASE_URL =
process.env.DATABASE_URL ?? "postgresql://localhost/nineoh_guide?host=/tmp";
const pool = new pg.Pool({ connectionString: DATABASE_URL });
const SHOW = {
canonical_title: "90210",
display_title: "90210 (2008)",
franchise_title: "Beverly Hills, 90210 franchise",
// ORIGINAL copy — written for this app, not a copied network synopsis.
description_original:
"A fan-made companion to the 2008 teen drama set in the 90210 ZIP code — " +
"an unofficial episode index, cast reference, and news feed. Every recap and " +
"bio here is written independently by our editors.",
disclaimer_text:
"Unofficial, fan-made. Not affiliated with or endorsed by the series' " +
"producers, network, or cast.",
};
const { rows } = await pool.query(
`insert into shows (canonical_title, display_title, franchise_title, description_original, disclaimer_text)
select $1,$2,$3,$4,$5
where not exists (select 1 from shows where canonical_title = $1)
returning id`,
[
SHOW.canonical_title,
SHOW.display_title,
SHOW.franchise_title,
SHOW.description_original,
SHOW.disclaimer_text,
]
);
const existing = rows[0]
? rows[0].id
: (await pool.query(`select id from shows where canonical_title=$1`, [SHOW.canonical_title])).rows[0].id;
console.log(rows[0] ? `seeded show ${existing}` : `show already present ${existing}`);
await pool.end();