Repository Public
1import "./_env";2import { sql, j } from "../src/lib/db";3import { COLLECTIONS, SERIES, TAGS } from "../src/lib/taxonomy";45/** Idempotent: upserts the editorial taxonomy (series templates, tag vocabulary, collections). */6async function main() {7 for (const [i, s] of SERIES.entries()) {8 await sql`INSERT INTO series (slug, title_en, title_fr, description_en, description_fr, kind, template, accent, sort)9 VALUES (${s.slug}, ${s.titleEn}, ${s.titleFr}, ${s.descriptionEn}, ${s.descriptionFr}, ${s.kind}, ${j({ rules: s.rules, defaultLanguage: s.defaultLanguage })}, ${s.accent}, ${i})10 ON CONFLICT (slug) DO UPDATE SET title_en = EXCLUDED.title_en, title_fr = EXCLUDED.title_fr, description_en = EXCLUDED.description_en,11 description_fr = EXCLUDED.description_fr, kind = EXCLUDED.kind, template = EXCLUDED.template, accent = EXCLUDED.accent, sort = EXCLUDED.sort`;12 }13 for (const t of TAGS) {14 await sql`INSERT INTO tags (slug, kind, label_en, label_fr) VALUES (${t.slug}, ${t.kind}, ${t.en}, ${t.fr})15 ON CONFLICT (slug) DO UPDATE SET kind = EXCLUDED.kind, label_en = EXCLUDED.label_en, label_fr = EXCLUDED.label_fr`;16 }17 for (const [i, c] of COLLECTIONS.entries()) {18 await sql`INSERT INTO collections (slug, title_en, title_fr, description_en, description_fr, sort) VALUES (${c.slug}, ${c.titleEn}, ${c.titleFr}, ${c.descriptionEn}, ${c.descriptionFr}, ${i})19 ON CONFLICT (slug) DO UPDATE SET title_en = EXCLUDED.title_en, title_fr = EXCLUDED.title_fr, description_en = EXCLUDED.description_en, description_fr = EXCLUDED.description_fr`;20 }21 console.log(`seeded ${SERIES.length} series, ${TAGS.length} tags, ${COLLECTIONS.length} collection(s)`);22 await sql.end();23}24main().catch((e) => { console.error(e.message); process.exit(1); });25