[object Object]

← back to Nineoh Guide

auto-save: 2026-08-05T15:43:31 (1 files) — db/ingest-original.mjs

f1299edc7589e66e88a729d444c899f4fe7d5257 · 2026-08-05 15:43:39 -0700 · Steve Abrams

Files touched

Diff

commit f1299edc7589e66e88a729d444c899f4fe7d5257
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Wed Aug 5 15:43:39 2026 -0700

    auto-save: 2026-08-05T15:43:31 (1 files) — db/ingest-original.mjs
---
 db/ingest-original.mjs | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/db/ingest-original.mjs b/db/ingest-original.mjs
index 72fe960..28c059a 100644
--- a/db/ingest-original.mjs
+++ b/db/ingest-original.mjs
@@ -103,26 +103,34 @@ try {
   for (let i = 0; i < castArr.length; i++) {
     const person = castArr[i]?.person, character = castArr[i]?.character;
     if (!person?.name) continue;
-    const pRow = (
+    // Upsert person by name (no external_ids column; names are facts).
+    let personId = (
       await pool.query(
-        `insert into cast_people (name, external_ids)
-         values ($1,$2)
-         on conflict (name) do update set external_ids = cast_people.external_ids || excluded.external_ids
-         returning id`,
-        [person.name, JSON.stringify({ tvmaze: String(person.id) })]
+        `insert into cast_people (name, publicity_risk_level)
+           select $1, 'editorial-only'
+           where not exists (select 1 from cast_people where name = $1)
+           returning id`,
+        [person.name]
       )
-    ).rows[0];
+    ).rows[0]?.id;
+    if (!personId) {
+      personId = (await pool.query(`select id from cast_people where name=$1`, [person.name])).rows[0].id;
+    }
+    const pRow = { id: personId };
     let charId = null;
     if (character?.name) {
       charId = (
         await pool.query(
-          `insert into characters (show_id, name)
-           values ($1,$2)
-           on conflict (show_id, name) do update set name = excluded.name
-           returning id`,
-          [showId, character.name]
+          `insert into characters (name, show_id)
+             select $1, $2
+             where not exists (select 1 from characters where name=$1 and show_id=$2)
+             returning id`,
+          [character.name, showId]
         )
-      ).rows[0].id;
+      ).rows[0]?.id;
+      if (!charId) {
+        charId = (await pool.query(`select id from characters where name=$1 and show_id=$2`, [character.name, showId])).rows[0].id;
+      }
     }
     await pool.query(
       `insert into credits (show_id, person_id, character_id, credit_type, billing_order)

← 70d794a TK-12: remove committed ios/ from git — was making EAS treat  ·  back to Nineoh Guide  ·  analytics: wire Firebase Analytics (→GA4) + Crashlytics into 702110a →