maintenance: cerrar whitelist del fresh-start
Ajusta el preview para limpiar también Departamentos importados, conservar sólo estructura sembrada y reiniciar configuración institucional editable. Reactiva FK antes de eliminar usuarios.
This commit is contained in:
@@ -18,8 +18,10 @@ const PRESERVED_TABLES = new Set([
|
||||
'asset_attribute_definitions',
|
||||
'finding_categories',
|
||||
'finding_catalog_items',
|
||||
'finding_catalog_item_versions',
|
||||
'finding_catalog_item_asset_types',
|
||||
'finding_catalog_asset_type_profiles',
|
||||
'institutional_delivery_settings',
|
||||
]);
|
||||
|
||||
type AdminRow = {
|
||||
@@ -126,6 +128,7 @@ async function main(): Promise<void> {
|
||||
for (const table of tablesToPreserve) {
|
||||
process.stdout.write(`KEEP ${table.padEnd(46)} ${await rowCount(table)}\n`);
|
||||
}
|
||||
process.stdout.write('RESET institutional_delivery_settings emails/updated_by\n');
|
||||
|
||||
process.stdout.write('\n========== DATOS A ELIMINAR ==========\n');
|
||||
let rowsToDelete = 0;
|
||||
@@ -147,12 +150,28 @@ async function main(): Promise<void> {
|
||||
}
|
||||
|
||||
await migrationDataSource.transaction(async (manager) => {
|
||||
// Se vacía el grafo operacional completo sin depender del orden físico
|
||||
// de las FK. La estructura maestra está excluida por PRESERVED_TABLES.
|
||||
await manager.query(`SET LOCAL session_replication_role = replica`);
|
||||
|
||||
for (const table of tablesToClear) {
|
||||
await manager.query(`DELETE FROM public.${quoteIdentifier(table)}`);
|
||||
}
|
||||
|
||||
// Antes de tocar cualquier tabla preservada reactivamos las FK reales.
|
||||
// Si apareciera una dependencia RESTRICT inesperada, PostgreSQL aborta
|
||||
// la transacción completa en lugar de dejar referencias huérfanas.
|
||||
await manager.query(`SET LOCAL session_replication_role = origin`);
|
||||
|
||||
await manager.query(`
|
||||
UPDATE institutional_delivery_settings
|
||||
SET office_email = NULL,
|
||||
director_email = NULL,
|
||||
updated_by = NULL,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = 1
|
||||
`);
|
||||
|
||||
await manager.query(
|
||||
`DELETE FROM user_roles WHERE user_id <> $1::uuid`,
|
||||
[admin.id],
|
||||
@@ -224,7 +243,8 @@ async function main(): Promise<void> {
|
||||
process.stdout.write('\n========== VERIFICACIÓN FRESH START ==========\n');
|
||||
process.stdout.write(`Usuarios: 1 (${admin.username})\n`);
|
||||
process.stdout.write('Datos operativos/importados: 0\n');
|
||||
process.stdout.write('Roles/permisos/tipos/catálogos estructurales: conservados\n');
|
||||
process.stdout.write('Roles/permisos/tipos/catálogo base: conservados\n');
|
||||
process.stdout.write('Configuración institucional editable: reiniciada\n');
|
||||
process.stdout.write('FRESH_START_OK\n');
|
||||
} finally {
|
||||
if (migrationDataSource.isInitialized) {
|
||||
|
||||
Reference in New Issue
Block a user