feat(inventory): add function catalog and act data
DH V2 CI / WEB · typecheck, build (push) Successful in 45s
Production dependency audit / API · production dependencies (push) Successful in 27s
DH V2 CI / API · typecheck, tests, build (push) Successful in 1m15s
Production dependency audit / WEB · production dependencies (push) Successful in 15s
DH V2 CI / Docker / migrations / production images (push) Successful in 2m21s
DH V2 CI / Promote verified main to deploy (push) Successful in 9s
Android CI / RC / Android · lint, tests, debug APK, release compile (push) Failing after 6m25s
DH V2 CI / WEB · typecheck, build (push) Successful in 45s
Production dependency audit / API · production dependencies (push) Successful in 27s
DH V2 CI / API · typecheck, tests, build (push) Successful in 1m15s
Production dependency audit / WEB · production dependencies (push) Successful in 15s
DH V2 CI / Docker / migrations / production images (push) Successful in 2m21s
DH V2 CI / Promote verified main to deploy (push) Successful in 9s
Android CI / RC / Android · lint, tests, debug APK, release compile (push) Failing after 6m25s
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class F618FunctionCatalog1790146200000 implements MigrationInterface {
|
||||
name = 'F618FunctionCatalog1790146200000';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
UPDATE asset_attribute_definitions definition
|
||||
SET is_required=false, updated_at=CURRENT_TIMESTAMP
|
||||
FROM asset_types type
|
||||
WHERE type.id=definition.asset_type_id
|
||||
AND lower(type.code) IN ('instalacion','subinstalacion')
|
||||
`);
|
||||
|
||||
await queryRunner.query(`
|
||||
WITH legacy AS (
|
||||
SELECT DISTINCT trim(value.value #>> '{}') AS name
|
||||
FROM asset_attribute_values value
|
||||
JOIN asset_attribute_definitions definition ON definition.id=value.definition_id
|
||||
JOIN asset_types type ON type.id=definition.asset_type_id
|
||||
WHERE definition.code='campo_funcion'
|
||||
AND lower(type.code) IN ('instalacion','subinstalacion')
|
||||
AND nullif(trim(value.value #>> '{}'),'') IS NOT NULL
|
||||
)
|
||||
INSERT INTO inventory_functions(code,name,description,is_active,sort_order)
|
||||
SELECT 'MIGRATED_' || upper(substr(md5(lower(name)),1,12)), name,
|
||||
'Migrada desde el campo libre Función al catálogo F6.18.', true, 9000
|
||||
FROM legacy
|
||||
ON CONFLICT (code) DO UPDATE SET name=EXCLUDED.name,is_active=true,updated_at=CURRENT_TIMESTAMP
|
||||
`);
|
||||
|
||||
await queryRunner.query(`
|
||||
INSERT INTO inventory_function_assignments(asset_id,function_id,valid_from,change_reason)
|
||||
SELECT value.asset_id,function.id,COALESCE(value.updated_at,CURRENT_TIMESTAMP),'Migrado desde campo_funcion F6.18'
|
||||
FROM asset_attribute_values value
|
||||
JOIN asset_attribute_definitions definition ON definition.id=value.definition_id
|
||||
JOIN asset_types type ON type.id=definition.asset_type_id
|
||||
JOIN inventory_functions function
|
||||
ON function.code='MIGRATED_' || upper(substr(md5(lower(trim(value.value #>> '{}'))),1,12))
|
||||
WHERE definition.code='campo_funcion'
|
||||
AND lower(type.code) IN ('instalacion','subinstalacion')
|
||||
AND nullif(trim(value.value #>> '{}'),'') IS NOT NULL
|
||||
ON CONFLICT (asset_id) WHERE valid_until IS NULL DO NOTHING
|
||||
`);
|
||||
|
||||
await queryRunner.query(`
|
||||
UPDATE asset_attribute_definitions definition
|
||||
SET is_active=false,is_required=false,updated_at=CURRENT_TIMESTAMP
|
||||
FROM asset_types type
|
||||
WHERE type.id=definition.asset_type_id
|
||||
AND lower(type.code) IN ('instalacion','subinstalacion')
|
||||
AND definition.code='campo_funcion'
|
||||
`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
UPDATE asset_attribute_definitions definition
|
||||
SET is_active=true,is_required=false,updated_at=CURRENT_TIMESTAMP
|
||||
FROM asset_types type
|
||||
WHERE type.id=definition.asset_type_id
|
||||
AND lower(type.code) IN ('instalacion','subinstalacion')
|
||||
AND definition.code='campo_funcion'
|
||||
`);
|
||||
|
||||
await queryRunner.query(`
|
||||
INSERT INTO asset_attribute_values(asset_id,definition_id,value,updated_at)
|
||||
SELECT assignment.asset_id,definition.id,to_jsonb(function.name),CURRENT_TIMESTAMP
|
||||
FROM inventory_function_assignments assignment
|
||||
JOIN inventory_functions function ON function.id=assignment.function_id
|
||||
JOIN assets asset ON asset.id=assignment.asset_id
|
||||
JOIN asset_types type ON type.id=asset.asset_type_id
|
||||
JOIN asset_attribute_definitions definition
|
||||
ON definition.asset_type_id=asset.asset_type_id AND definition.code='campo_funcion'
|
||||
WHERE assignment.change_reason='Migrado desde campo_funcion F6.18'
|
||||
AND assignment.valid_until IS NULL
|
||||
ON CONFLICT (asset_id,definition_id) DO UPDATE SET value=EXCLUDED.value,updated_at=CURRENT_TIMESTAMP
|
||||
`);
|
||||
|
||||
await queryRunner.query(`DELETE FROM inventory_function_assignments WHERE change_reason='Migrado desde campo_funcion F6.18'`);
|
||||
await queryRunner.query(`
|
||||
DELETE FROM inventory_functions function
|
||||
WHERE function.code LIKE 'MIGRATED_%'
|
||||
AND NOT EXISTS (SELECT 1 FROM inventory_function_assignments assignment WHERE assignment.function_id=function.id)
|
||||
`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user