fix7
This commit is contained in:
1 parent
d62f4a3227
commit
d74af3bf65
1 file changed
+19
-1
@@ -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");
|
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) {
|
} catch (err) {
|
||||||
await client.query("ROLLBACK");
|
await client.query("ROLLBACK");
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|||||||
Reference in new issue
Block a user