From d74af3bf653671432fb45755d38a2ac392d795fa Mon Sep 17 00:00:00 2001 From: Rodrigo Bertoldo de Sousa Martins Date: Tue, 8 Sep 2026 14:35:58 -0300 Subject: [PATCH] fix7 --- data-pipeline/scripts/seed-db.mjs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/data-pipeline/scripts/seed-db.mjs b/data-pipeline/scripts/seed-db.mjs index bcc696c..55f287d 100644 --- a/data-pipeline/scripts/seed-db.mjs +++ b/data-pipeline/scripts/seed-db.mjs @@ -88,8 +88,26 @@ try { ); } + // O manifesto de cada execução é sempre completo (cobre todos os + // sistemas) — qualquer coisa no banco cujo slug não está mais nele é + // obsoleta (ex: itens excluídos por um filtro/curadoria novos) e deve + // ser removida, senão elas só se acumulam a cada execução do pipeline. + const currentSlugs = structures.map((s) => s.slug); + await client.query( + `DELETE FROM quiz_cards WHERE "structureId" IN ( + SELECT id FROM structures WHERE NOT (slug = ANY($1::text[])) + )`, + [currentSlugs], + ); + const { rowCount: removed } = await client.query( + `DELETE FROM structures WHERE NOT (slug = ANY($1::text[]))`, + [currentSlugs], + ); + await client.query("COMMIT"); - console.log(`Seed concluído: ${systems.length} sistemas, ${structures.length} estruturas.`); + console.log( + `Seed concluído: ${systems.length} sistemas, ${structures.length} estruturas (${removed} obsoletas removidas).`, + ); } catch (err) { await client.query("ROLLBACK"); console.error(err);