From 42f7c9bac667948d238945b17c2d4a048564ae00 Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Tue, 7 Apr 2026 11:10:42 +0200 Subject: [PATCH] feat: add sync script for advertising tables from MSSQL to PostgreSQL --- sync/tables/publicites.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sync/tables/publicites.js b/sync/tables/publicites.js index 8b76409..68f01e1 100644 --- a/sync/tables/publicites.js +++ b/sync/tables/publicites.js @@ -70,7 +70,11 @@ async function syncPublicites(force) { FROM FBENTPUB `); - const rows = res.recordset.map(r => ({ + // Dédoublonnage sur ENT_NPUB (doublons présents côté SQL Server) + const seen = new Set(); + const rows = res.recordset + .filter(r => { const k = String(r.ENT_NPUB); if (seen.has(k)) return false; seen.add(k); return true; }) + .map(r => ({ ent_npub: String(r.ENT_NPUB), ent_datdeb: r.ENT_DATDEB && r.ENT_DATDEB.getFullYear() > 1901 ? r.ENT_DATDEB : null, ent_datfin: r.ENT_DATFIN && r.ENT_DATFIN.getFullYear() > 1901 ? r.ENT_DATFIN : null, @@ -78,6 +82,7 @@ async function syncPublicites(force) { })); await pg.query('TRUNCATE TABLE pub_entetes'); + for (let i = 0; i < rows.length; i += CHUNK) { const chunk = rows.slice(i, i + CHUNK); const values = [];