Skip to content

Commit

Permalink
Merge pull request #1964 from bcgov/feature/ALCS-2147
Browse files Browse the repository at this point in the history
Migrate decision NARU subtypes to tags
  • Loading branch information
trslater authored Nov 6, 2024
2 parents ca24469 + bb5178f commit 935fa4a
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class MigrateDecisionNaruSubtypesToTags1730926552631 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
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
)
insert into alcs.application_tag (application_uuid, tag_uuid)
select rc.application_uuid, t."uuid"
from ranked_components rc
join alcs.tag t on case
when rc.naru_subtype_code = 'ARFU' then 'Additional Residence'
when rc.naru_subtype_code = 'PRIN' then 'Principal Residence > 500m2'
when rc.naru_subtype_code = 'TOUR' then 'Tourism'
end = t.name
where rc.rank = 1
on conflict do nothing
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {}
}

0 comments on commit 935fa4a

Please sign in to comment.