← back to Designer Wallcoverings
AF staging fixer: route mfr_sku UNIQUE collisions (phantom AT dups of existing AF rows) to anomalies instead of erroring
91749a79c07dd8e8617fa3690be018da0be7215a · 2026-06-25 11:26:31 -0700 · Steve Abrams
Files touched
M shopify/scripts/anna-french-fix-staging-anomalies.mjs
Diff
commit 91749a79c07dd8e8617fa3690be018da0be7215a
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Thu Jun 25 11:26:31 2026 -0700
AF staging fixer: route mfr_sku UNIQUE collisions (phantom AT dups of existing AF rows) to anomalies instead of erroring
---
shopify/scripts/anna-french-fix-staging-anomalies.mjs | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/shopify/scripts/anna-french-fix-staging-anomalies.mjs b/shopify/scripts/anna-french-fix-staging-anomalies.mjs
index 312c48e7..dea9d022 100644
--- a/shopify/scripts/anna-french-fix-staging-anomalies.mjs
+++ b/shopify/scripts/anna-french-fix-staging-anomalies.mjs
@@ -298,10 +298,13 @@ async function run() {
`SELECT id, mfr_sku, dw_sku, dw_prefix, product_type, color_name FROM anna_french_catalog`
);
const stageByMfr = new Map();
+ const stageIdsByMfr = new Map(); // upper(mfr) -> Set<id> (collision detection across the whole table)
for (const r of stageRows) {
const k = String(r.mfr_sku || '').toUpperCase();
if (!stageByMfr.has(k)) stageByMfr.set(k, []);
stageByMfr.get(k).push(r);
+ if (!stageIdsByMfr.has(k)) stageIdsByMfr.set(k, new Set());
+ stageIdsByMfr.get(k).add(r.id);
}
let i = 0;
@@ -337,6 +340,22 @@ async function run() {
const newMfr = d.true_mfr;
for (const row of stageMatches) {
+ // mfr_sku has a UNIQUE constraint. If the target mfr already exists as a
+ // DIFFERENT staging row, this AT row is a redundant phantom duplicate of an
+ // already-correct AF row — flipping it would violate the constraint and would
+ // create a duplicate. Leave it for human review (do NOT guess a dedup flag).
+ const targetKey = newMfr.toUpperCase();
+ const ownerIds = stageIdsByMfr.get(targetKey);
+ const collidesWithOther = ownerIds && [...ownerIds].some((x) => x !== row.id);
+ if (collidesWithOther) {
+ audit.left_as_anomaly.push({
+ mfr_sku: row.mfr_sku,
+ reason: a.reason,
+ why: `target mfr ${newMfr} already exists as staging row(s) ${[...ownerIds].filter((x) => x !== row.id).join(',')} (phantom duplicate of an already-correct ${newPrefix} row) — needs human dedup decision`,
+ });
+ continue;
+ }
+
const curType = row.product_type;
const curMfr = String(row.mfr_sku || '').toUpperCase();
const curPrefix = (row.dw_prefix || '').toUpperCase();
← 449e1cc6 Add Anna French staging anomaly fixer (AT<->AF type/prefix/d
·
back to Designer Wallcoverings
·
auto-save: 2026-06-25T11:33:53 (5 files) — pending-approval/ bd605d24 →