From 3297dfca45d2470414e4ac69bd983233cd3bcd5c Mon Sep 17 00:00:00 2001 From: enlineawork Date: Wed, 9 Sep 2026 08:47:40 -0300 Subject: [PATCH] fix(f5.1): allow inventory area context without operator --- .../1790087400000-f5-1-clean-manual-inventory.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/api-v3/src/database/migrations/1790087400000-f5-1-clean-manual-inventory.ts b/api-v3/src/database/migrations/1790087400000-f5-1-clean-manual-inventory.ts index f73441f..e3379de 100644 --- a/api-v3/src/database/migrations/1790087400000-f5-1-clean-manual-inventory.ts +++ b/api-v3/src/database/migrations/1790087400000-f5-1-clean-manual-inventory.ts @@ -48,6 +48,20 @@ export class F51CleanManualInventory1790087400000 implements MigrationInterface END $$; `); + // F5.1 decouples the physical Inventory tree from Empresa. A structural + // Asset may therefore inherit an Area while no operator has been assigned + // yet. Keep the useful invariant that an operator can never exist without + // an Area, but remove the old all-or-nothing pair requirement. + await queryRunner.query(` + ALTER TABLE asset_context_history + DROP CONSTRAINT IF EXISTS chk_asset_context_history_context_pair + `); + await queryRunner.query(` + ALTER TABLE asset_context_history + ADD CONSTRAINT chk_asset_context_history_context_pair + CHECK (operator_company_id IS NULL OR operational_area_id IS NOT NULL) + `); + // Departamento becomes the real root of the physical Inventory tree. await queryRunner.query(` INSERT INTO asset_types(code,name,description,can_be_root,is_active,operational_role)