Precarga únicamente la fuente aprobada Tablas de yacimiento y areas(1).xlsx con jerarquía Departamento → Área → Yacimiento, concesiones y Operadoras. Corrige además el CHECK legacy F4 para permitir contexto físico de Área sin snapshot obligatorio de Empresa. El reset preserva usuarios/RBAC y catálogos/configuración técnica, y valida cardinalidades exactas antes de completar.
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
|
|
/**
|
|
* F5/F6 permits physical Inventory to belong to an Área without persisting a
|
|
* Company snapshot. Company snapshots are optional creation/history metadata;
|
|
* current ownership is resolved from area_company_relations.
|
|
*
|
|
* The F4 paired CHECK survived the trigger migration and contradicted that
|
|
* model. Keep only the invariant that a Company snapshot cannot exist without
|
|
* an Área.
|
|
*/
|
|
export class F61AreaOwnedOperationalContextCheck1790094500000 implements MigrationInterface {
|
|
name='F61AreaOwnedOperationalContextCheck1790094500000';
|
|
|
|
public async up(queryRunner:QueryRunner):Promise<void>{
|
|
await queryRunner.query('ALTER TABLE assets DROP CONSTRAINT IF EXISTS chk_assets_operational_assignment_pair');
|
|
await queryRunner.query(`
|
|
ALTER TABLE assets
|
|
ADD CONSTRAINT chk_assets_operational_assignment_pair
|
|
CHECK (operator_company_id IS NULL OR operational_area_id IS NOT NULL)
|
|
`);
|
|
}
|
|
|
|
public async down(queryRunner:QueryRunner):Promise<void>{
|
|
await queryRunner.query('ALTER TABLE assets DROP CONSTRAINT IF EXISTS chk_assets_operational_assignment_pair');
|
|
await queryRunner.query(`
|
|
ALTER TABLE assets
|
|
ADD CONSTRAINT chk_assets_operational_assignment_pair
|
|
CHECK (
|
|
(operational_area_id IS NULL AND operator_company_id IS NULL)
|
|
OR (operational_area_id IS NOT NULL AND operator_company_id IS NOT NULL)
|
|
)
|
|
`);
|
|
}
|
|
}
|