[object Object]

← back to Crezana Scraper

Scraper auto-assign back to DWCZ-###### 6-digit (never collection letters)

2098191af35d4aa8a8d11528bc3c9ea3088dd9a8 · 2026-07-14 13:01:09 -0700 · Steve Abrams

Files touched

Diff

commit 2098191af35d4aa8a8d11528bc3c9ea3088dd9a8
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Tue Jul 14 13:01:09 2026 -0700

    Scraper auto-assign back to DWCZ-###### 6-digit (never collection letters)
---
 scrape.mjs | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/scrape.mjs b/scrape.mjs
index 7e331bc..03fa206 100644
--- a/scrape.mjs
+++ b/scrape.mjs
@@ -136,31 +136,24 @@ async function main() {
     if (r.rows[0].inserted) ins++; else upd++;
   }
 
-  // Assign collection-encoded DW series SKUs (DWCZ-<CODE>-NNN) to any rows still
-  // missing one — NNN continues from that collection's current max, so the series
-  // never regresses to NULL and never collides. Idempotent: a normal re-run touches
-  // 0 rows since every existing row already carries a dw_sku.
+  // Assign DW series SKUs (DWCZ- + 6-digit number) to any rows still missing one —
+  // continue from the current max so the series never regresses to NULL and never
+  // collides. HARD RULE (Steve): DWCZ-###### 6-digit numbers ONLY, never collection
+  // letters. Idempotent: a normal re-run touches 0 rows.
   const dw = await client.query(`
-    WITH code(collection, c) AS (VALUES
-      ('Home','HOM'),('Printed','PRT'),('Textures','TEX'),
-      ('Embroideries','EMB'),('Embroideries II','EM2'),
-      ('Madagascars','MAD'),('Grommets & Studs','GRO')),
-    mx AS (
-      SELECT collection, MAX((regexp_replace(dw_sku,'^DWCZ-[A-Z0-9]{3}-',''))::int) AS n
-      FROM crezana_catalog WHERE dw_sku ~ '^DWCZ-[A-Z0-9]{3}-[0-9]+$' GROUP BY collection
+    WITH mx AS (
+      SELECT COALESCE(MAX((regexp_replace(dw_sku,'^DWCZ-',''))::int), 890999) AS n
+      FROM crezana_catalog WHERE dw_sku ~ '^DWCZ-[0-9]{6}$'
     ),
     todo AS (
-      SELECT cc.id, k.c AS code,
-             COALESCE((SELECT n FROM mx WHERE mx.collection = cc.collection), 0)
-             + row_number() OVER (PARTITION BY cc.collection ORDER BY cc.id) AS seq
-      FROM crezana_catalog cc JOIN code k ON k.collection = cc.collection
-      WHERE cc.dw_sku IS NULL
+      SELECT id, (SELECT n FROM mx) + row_number() OVER (ORDER BY id) AS seq
+      FROM crezana_catalog WHERE dw_sku IS NULL
     )
     UPDATE crezana_catalog c
-    SET dw_sku = 'DWCZ-' || todo.code || '-' || lpad(todo.seq::text, 3, '0'), updated_at = now()
+    SET dw_sku = 'DWCZ-' || todo.seq, updated_at = now()
     FROM todo WHERE c.id = todo.id
     RETURNING c.id`);
-  if (dw.rowCount) console.log(`Assigned ${dw.rowCount} new DWCZ-<coll>-NNN series SKU(s).`);
+  if (dw.rowCount) console.log(`Assigned ${dw.rowCount} new DWCZ-###### series SKU(s).`);
 
   await client.end();
   console.log(`Upserted: ${ins} inserted, ${upd} updated. Cost: $0 (local)`);

← 9917ba6 Auto-assign collection-encoded DWCZ-<coll>-NNN to new rows (  ·  back to Crezana Scraper  ·  chore: v1.1.0 (session close — auto-assign DWCZ-###### 6-dig ab5280b →