From cb0b608edb2b4cd99120e6c7700367b0c86b2586 Mon Sep 17 00:00:00 2001 From: Michael SCHAL Date: Wed, 1 Apr 2026 10:18:12 +0200 Subject: [PATCH] feat: implement synchronization logic for mouvements and statopca tables from MSSQL to PostgreSQL --- sync/tables/mouvements.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sync/tables/mouvements.js b/sync/tables/mouvements.js index 915978c..5467677 100644 --- a/sync/tables/mouvements.js +++ b/sync/tables/mouvements.js @@ -16,7 +16,7 @@ const MVTREG_COLS = [ const CHUNK = 2000; -async function insertChunk(pg, table, rows, cols) { +async function insertChunk(pg, table, rows, cols, conflictTarget = null) { if (!rows.length) return; const values = []; const placeholders = rows.map((row, ri) => { @@ -26,8 +26,9 @@ async function insertChunk(pg, table, rows, cols) { }); return `(${ph.join(', ')})`; }); + const conflict = conflictTarget ? `ON CONFLICT (${conflictTarget}) DO NOTHING` : ''; await pg.query( - `INSERT INTO ${table} (${cols.join(', ')}) VALUES ${placeholders.join(', ')} ON CONFLICT (no_id) DO NOTHING`, + `INSERT INTO ${table} (${cols.join(', ')}) VALUES ${placeholders.join(', ')} ${conflict}`, values ); } @@ -78,7 +79,7 @@ async function syncMouvements(force) { let inserted = 0; for (let i = 0; i < allRows.length; i += CHUNK) { - await insertChunk(pg, 'mvtart', allRows.slice(i, i + CHUNK), MVTART_COLS); + await insertChunk(pg, 'mvtart', allRows.slice(i, i + CHUNK), MVTART_COLS, 'no_id'); inserted += Math.min(CHUNK, allRows.length - i); }