From 46bcca8a2a60f4707c0d33a7686bcd33c43e4aad Mon Sep 17 00:00:00 2001 From: Tristan Slater <1631008+trslater@users.noreply.github.com> Date: Wed, 6 Nov 2024 13:49:09 -0800 Subject: [PATCH] Fix possibly adding deleted tags --- ...31-migrate_decision_naru_subtypes_to_tags.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/services/apps/alcs/src/providers/typeorm/migrations/1730926552631-migrate_decision_naru_subtypes_to_tags.ts b/services/apps/alcs/src/providers/typeorm/migrations/1730926552631-migrate_decision_naru_subtypes_to_tags.ts index 2d33133d1e..e611ca1e6a 100644 --- a/services/apps/alcs/src/providers/typeorm/migrations/1730926552631-migrate_decision_naru_subtypes_to_tags.ts +++ b/services/apps/alcs/src/providers/typeorm/migrations/1730926552631-migrate_decision_naru_subtypes_to_tags.ts @@ -4,14 +4,14 @@ export class MigrateDecisionNaruSubtypesToTags1730926552631 implements Migration public async up(queryRunner: QueryRunner): Promise { queryRunner.query(` with ranked_components as ( - select ad.application_uuid, - adc.naru_subtype_code, - rank() over (partition by ad.application_uuid order by ad.date) - from alcs.application_decision ad - join alcs.application_decision_component adc on adc.application_decision_uuid = ad."uuid" - where ad.is_draft is false - and adc.application_decision_component_type_code = 'NARU' - and adc.naru_subtype_code is not null + select ad.application_uuid, + adc.naru_subtype_code, + rank() over (partition by ad.application_uuid order by ad.date) + from alcs.application_decision ad + join alcs.application_decision_component adc on adc.application_decision_uuid = ad."uuid" + where ad.is_draft is false + and adc.application_decision_component_type_code = 'NARU' + and adc.naru_subtype_code is not null ) insert into alcs.application_tag (application_uuid, tag_uuid) select rc.application_uuid, t."uuid" @@ -22,6 +22,7 @@ export class MigrateDecisionNaruSubtypesToTags1730926552631 implements Migration when rc.naru_subtype_code = 'TOUR' then 'Tourism' end = t.name where rc.rank = 1 + and t.audit_deleted_date_at is null on conflict do nothing `); }