Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21127b8cff | ||
|
|
50a9dc5183 | ||
|
|
a69df1d2d6 |
@@ -18,8 +18,10 @@ const PRESERVED_TABLES = new Set([
|
|||||||
'asset_attribute_definitions',
|
'asset_attribute_definitions',
|
||||||
'finding_categories',
|
'finding_categories',
|
||||||
'finding_catalog_items',
|
'finding_catalog_items',
|
||||||
|
'finding_catalog_item_versions',
|
||||||
'finding_catalog_item_asset_types',
|
'finding_catalog_item_asset_types',
|
||||||
'finding_catalog_asset_type_profiles',
|
'finding_catalog_asset_type_profiles',
|
||||||
|
'institutional_delivery_settings',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
type AdminRow = {
|
type AdminRow = {
|
||||||
@@ -126,6 +128,7 @@ async function main(): Promise<void> {
|
|||||||
for (const table of tablesToPreserve) {
|
for (const table of tablesToPreserve) {
|
||||||
process.stdout.write(`KEEP ${table.padEnd(46)} ${await rowCount(table)}\n`);
|
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');
|
process.stdout.write('\n========== DATOS A ELIMINAR ==========\n');
|
||||||
let rowsToDelete = 0;
|
let rowsToDelete = 0;
|
||||||
@@ -147,12 +150,28 @@ async function main(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await migrationDataSource.transaction(async (manager) => {
|
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`);
|
await manager.query(`SET LOCAL session_replication_role = replica`);
|
||||||
|
|
||||||
for (const table of tablesToClear) {
|
for (const table of tablesToClear) {
|
||||||
await manager.query(`DELETE FROM public.${quoteIdentifier(table)}`);
|
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(
|
await manager.query(
|
||||||
`DELETE FROM user_roles WHERE user_id <> $1::uuid`,
|
`DELETE FROM user_roles WHERE user_id <> $1::uuid`,
|
||||||
[admin.id],
|
[admin.id],
|
||||||
@@ -224,7 +243,8 @@ async function main(): Promise<void> {
|
|||||||
process.stdout.write('\n========== VERIFICACIÓN FRESH START ==========\n');
|
process.stdout.write('\n========== VERIFICACIÓN FRESH START ==========\n');
|
||||||
process.stdout.write(`Usuarios: 1 (${admin.username})\n`);
|
process.stdout.write(`Usuarios: 1 (${admin.username})\n`);
|
||||||
process.stdout.write('Datos operativos/importados: 0\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');
|
process.stdout.write('FRESH_START_OK\n');
|
||||||
} finally {
|
} finally {
|
||||||
if (migrationDataSource.isInitialized) {
|
if (migrationDataSource.isInitialized) {
|
||||||
|
|||||||
Reference in New Issue
Block a user