-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2038 from bcgov/feature/ALCS-1949
Move all security amounts to bond conditions
- Loading branch information
Showing
4 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
...cs/src/providers/typeorm/migrations/1734644882049-create_bond_conditions_where_missing.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class CreateBondConditionsWhereMissing1734644882049 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
// Applications | ||
queryRunner.query(` | ||
insert into | ||
alcs.application_decision_condition ( | ||
audit_created_by, | ||
decision_uuid, | ||
security_amount, | ||
type_code | ||
) | ||
select | ||
distinct 'oats_etl' as audit_created_by, | ||
ad."uuid" as decision_uuid, | ||
oaad.security_amt as security_amount, | ||
'BOND' as type_code | ||
from | ||
alcs.application_decision ad | ||
join alcs.application_decision_condition adc on ad.uuid = adc.decision_uuid | ||
right join oats.oats_alr_appl_decisions oaad on oaad.alr_appl_decision_id = ad.oats_alr_appl_decision_id | ||
where | ||
ad."uuid" not in ( | ||
select | ||
adc.decision_uuid | ||
from | ||
alcs.application_decision_condition adc | ||
where | ||
adc.type_code = 'BOND' | ||
) | ||
and adc.security_amount > 0 | ||
and ad.audit_created_by = 'oats_etl' | ||
and ( | ||
oaad.security_amt = adc.security_amount | ||
or adc.security_amount is null | ||
) on conflict ("uuid") do nothing; | ||
`); | ||
|
||
// NOI's | ||
queryRunner.query(` | ||
insert into | ||
alcs.notice_of_intent_decision_condition ( | ||
audit_created_by, | ||
decision_uuid, | ||
security_amount, | ||
type_code | ||
) | ||
select | ||
distinct 'oats_etl' as audit_created_by, | ||
noid."uuid" as decision_uuid, | ||
oaad.security_amt as security_amount, | ||
'BOND' as type_code | ||
from | ||
alcs.notice_of_intent_decision noid | ||
join alcs.notice_of_intent_decision_condition noidc on noid.uuid = noidc.decision_uuid | ||
right join oats.oats_alr_appl_decisions oaad on oaad.alr_appl_decision_id = noid.oats_alr_appl_decision_id | ||
where | ||
noid."uuid" not in ( | ||
select | ||
noidc.decision_uuid | ||
from | ||
alcs.notice_of_intent_decision_condition noidc | ||
where | ||
noidc.type_code = 'BOND' | ||
) | ||
and noidc.security_amount > 0 | ||
and noid.audit_created_by = 'oats_etl' | ||
and ( | ||
oaad.security_amt = noidc.security_amount | ||
or noidc.security_amount is null | ||
) on conflict ("uuid") do nothing; | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> {} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ders/typeorm/migrations/1734645250139-nullify_security_amounts_for_non_bond_conditions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class NullifySecurityAmountsForNonBondConditions1734645250139 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
// Apps | ||
queryRunner.query(` | ||
update | ||
alcs.application_decision_condition | ||
set | ||
security_amount = null | ||
where | ||
type_code <> 'BOND'; | ||
`); | ||
|
||
// NOI's | ||
queryRunner.query(` | ||
update | ||
alcs.notice_of_intent_decision_condition | ||
set | ||
security_amount = null | ||
where | ||
type_code <> 'BOND'; | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> {} | ||
} |
29 changes: 29 additions & 0 deletions
29
...eorm/migrations/1734646226612-disable_security_amount_for_all_non_bond_condition_types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class DisableSecurityAmountForAllNonBondConditionTypes1734646226612 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
// Apps | ||
queryRunner.query(` | ||
update | ||
alcs.application_decision_condition_type | ||
set | ||
is_security_amount_checked = false, | ||
is_security_amount_required = false | ||
where | ||
code <> 'BOND'; | ||
`); | ||
|
||
// NOI's | ||
queryRunner.query(` | ||
update | ||
alcs.notice_of_intent_decision_condition_type | ||
set | ||
is_security_amount_checked = false, | ||
is_security_amount_required = false | ||
where | ||
code <> 'BOND'; | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> {} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ypeorm/migrations/1734646507149-enable_required_secuity_amount_for_bond_condition_type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class EnableRequiredSecuityAmountForBondConditionType1734646507149 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
// Apps | ||
queryRunner.query(` | ||
update | ||
alcs.application_decision_condition_type | ||
set | ||
is_security_amount_checked = true, | ||
is_security_amount_required = true | ||
where | ||
code = 'BOND'; | ||
`); | ||
|
||
// NOI's | ||
queryRunner.query(` | ||
update | ||
alcs.notice_of_intent_decision_condition_type | ||
set | ||
is_security_amount_checked = true, | ||
is_security_amount_required = true | ||
where | ||
code = 'BOND'; | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> {} | ||
} |