← back to Filemaker Mcp
scripts/dedup-dwpp-32837.mjs
31 lines
// Dedup the two DWPP masters duplicated during the 32837 order fix (FileMaker Cloud
// create-then-find index latency minted a 2nd master on the corrective re-run). For each,
// KEEP the fully-corrected master (vid MDCKEN + mfr in tags + Content) and archive+delete
// the blank straggler. Archive-first (restore JSON) per the sanctioned dedup pattern.
// node scripts/dedup-dwpp-32837.mjs # archive + delete
// node scripts/dedup-dwpp-32837.mjs --dry-run # show only
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
import { fileURLToPath } from 'node:url'; import { dirname, join } from 'node:path';
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
mkdirSync(join(ROOT, 'data'), { recursive: true });
for (const l of readFileSync(join(ROOT,'.env'),'utf8').split('\n')) { const m=l.match(/^([A-Z0-9_]+)=(.*)$/); if(m&&!process.env[m[1]])process.env[m[1]]=m[2].replace(/^['"]|['"]$/g,''); }
const DRY = process.argv.includes('--dry-run');
const { getRecord, deleteRecord } = await import('../src/fm-client.js');
const DB='WALLPAPER', L='Basic List of Fields', FULL='*List Wallpapers - Full View';
const DELETE=[{ sku:'DWPP-206897', keep:'539328', drop:'539333' },{ sku:'DWPP-205219', keep:'539329', drop:'539334' }];
for (const d of DELETE) {
// Safety: confirm the KEEP master still exists before deleting the DROP twin — guards
// against a keep/drop typo destroying the good record and leaving the stub.
const keepRec = await getRecord(DB, FULL, d.keep).catch(e=>({err:e.message}));
if (keepRec.err) { console.log(`${d.sku}: keep ${d.keep} not fetchable (${keepRec.err}) — ABORT this pair`); continue; }
const rec = await getRecord(DB, FULL, d.drop).catch(e=>({err:e.message}));
if (rec.err) { console.log(`${d.sku}: drop ${d.drop} not fetchable (${rec.err}) — skip`); continue; }
const arch = join(ROOT,'data',`deleted-record-${d.drop}-restore.json`);
writeFileSync(arch, JSON.stringify({ note:`DWPP dedup 32837 fix 2026-08-12; keep ${d.keep}`, db:DB, recordId:d.drop, record:rec }, null, 2));
console.log(`${d.sku}: ARCHIVED drop ${d.drop} -> ${arch}`);
if (DRY) { console.log(` [dry-run] would delete ${d.drop}, keep ${d.keep}`); continue; }
await deleteRecord(DB, L, d.drop);
try { await getRecord(DB, L, d.drop); console.log(` WARN: ${d.drop} still fetchable`); }
catch { console.log(` DELETED ${d.drop}; kept ${d.keep}`); }
}