-
Notifications
You must be signed in to change notification settings - Fork 2
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 #2246 from bcgov/fix/gwp-values-correction
Fix: gwp values correction
- Loading branch information
Showing
8 changed files
with
449 additions
and
0 deletions.
There are no files selected for viewing
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,12 @@ | ||
-- Deploy ggircs-portal:data/correct_gwp_values to pg | ||
-- requires: database_functions/correct_gwp_values | ||
|
||
begin; | ||
|
||
alter table ggircs_portal.form_result disable trigger _100_timestamps, disable trigger _immutable_form_result; | ||
|
||
select ggircs_portal_private.correct_gwp_values(); | ||
|
||
alter table ggircs_portal.form_result enable trigger _100_timestamps, enable trigger _immutable_form_result; | ||
|
||
commit; |
113 changes: 113 additions & 0 deletions
113
schema/deploy/database_functions/correct_gwp_values.sql
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,113 @@ | ||
-- Deploy ggircs-portal:database_functions/correct_gwp_values to pg | ||
|
||
/** | ||
Some applications during the 2023 reporting cycle (2022 reporting year) were created before the correct gwp | ||
values were applied, which means when the applications were initialized the old AR4 values were applied. | ||
This function updates the gwp values in place to the correct AR5 values. | ||
**/ | ||
|
||
begin; | ||
|
||
create or replace function ggircs_portal_private.correct_gwp_values() | ||
returns void as $$ | ||
|
||
-- CH4 | ||
update ggircs_portal.form_result | ||
set form_result = replace(form_result::text, '"gwp": 25', '"gwp": 28')::jsonb | ||
where application_id in ( | ||
select application_id | ||
from ggircs_portal.application_revision ar | ||
join ggircs_portal.application a | ||
on a.id = ar.application_id | ||
and a.reporting_year = 2022 | ||
and ar.created_at < '2023-05-30' and ar.created_at > '2023-04-01' | ||
) | ||
and form_id=2; | ||
-- N2O | ||
update ggircs_portal.form_result | ||
set form_result = replace(form_result::text, '"gwp": 298', '"gwp": 265')::jsonb | ||
where application_id in ( | ||
select application_id | ||
from ggircs_portal.application_revision ar | ||
join ggircs_portal.application a | ||
on a.id = ar.application_id | ||
and a.reporting_year = 2022 | ||
and ar.created_at < '2023-05-30' and ar.created_at > '2023-04-01' | ||
) | ||
and form_id=2; | ||
-- SF6 | ||
update ggircs_portal.form_result | ||
set form_result = replace(form_result::text, '"gwp": 22800', '"gwp": 23500')::jsonb | ||
where application_id in ( | ||
select application_id | ||
from ggircs_portal.application_revision ar | ||
join ggircs_portal.application a | ||
on a.id = ar.application_id | ||
and a.reporting_year = 2022 | ||
and ar.created_at < '2023-05-30' and ar.created_at > '2023-04-01' | ||
) | ||
and form_id=2; | ||
-- CF4 | ||
update ggircs_portal.form_result | ||
set form_result = replace(form_result::text, '"gwp": 7390', '"gwp": 6630')::jsonb | ||
where application_id in ( | ||
select application_id | ||
from ggircs_portal.application_revision ar | ||
join ggircs_portal.application a | ||
on a.id = ar.application_id | ||
and a.reporting_year = 2022 | ||
and ar.created_at < '2023-05-30' and ar.created_at > '2023-04-01' | ||
) | ||
and form_id=2; | ||
-- C2F6 | ||
update ggircs_portal.form_result | ||
set form_result = replace(form_result::text, '"gwp": 12200', '"gwp": 11100')::jsonb | ||
where application_id in ( | ||
select application_id | ||
from ggircs_portal.application_revision ar | ||
join ggircs_portal.application a | ||
on a.id = ar.application_id | ||
and a.reporting_year = 2022 | ||
and ar.created_at < '2023-05-30' and ar.created_at > '2023-04-01' | ||
) | ||
and form_id=2; | ||
-- CH2F2 | ||
update ggircs_portal.form_result | ||
set form_result = replace(form_result::text, '"gwp": 675', '"gwp": 677')::jsonb | ||
where application_id in ( | ||
select application_id | ||
from ggircs_portal.application_revision ar | ||
join ggircs_portal.application a | ||
on a.id = ar.application_id | ||
and a.reporting_year = 2022 | ||
and ar.created_at < '2023-05-30' and ar.created_at > '2023-04-01' | ||
) | ||
and form_id=2; | ||
-- CH2HF5 | ||
update ggircs_portal.form_result | ||
set form_result = replace(form_result::text, '"gwp": 3500', '"gwp": 3170')::jsonb | ||
where application_id in ( | ||
select application_id | ||
from ggircs_portal.application_revision ar | ||
join ggircs_portal.application a | ||
on a.id = ar.application_id | ||
and a.reporting_year = 2022 | ||
and ar.created_at < '2023-05-30' and ar.created_at > '2023-04-01' | ||
) | ||
and form_id=2; | ||
-- C2H2F4 | ||
update ggircs_portal.form_result | ||
set form_result = replace(form_result::text, '"gwp": 1430', '"gwp": 1300')::jsonb | ||
where application_id in ( | ||
select application_id | ||
from ggircs_portal.application_revision ar | ||
join ggircs_portal.application a | ||
on a.id = ar.application_id | ||
and a.reporting_year = 2022 | ||
and ar.created_at < '2023-05-30' and ar.created_at > '2023-04-01' | ||
) | ||
and form_id=2; | ||
|
||
$$ language sql volatile; | ||
|
||
commit; |
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,106 @@ | ||
-- Revert ggircs-portal:data/correct_gwp_values from pg | ||
|
||
begin; | ||
|
||
alter table ggircs_portal.form_result disable trigger _100_timestamps, disable trigger _immutable_form_result; | ||
|
||
-- CH4 | ||
update ggircs_portal.form_result | ||
set form_result = replace(form_result::text, '"gwp": 28', '"gwp": 25')::jsonb | ||
where application_id in ( | ||
select application_id | ||
from ggircs_portal.application_revision ar | ||
join ggircs_portal.application a | ||
on a.id = ar.application_id | ||
and a.reporting_year = 2022 | ||
and ar.created_at < '2023-05-30' and ar.created_at > '2023-04-01' | ||
) | ||
and form_id=2; | ||
-- N2O | ||
update ggircs_portal.form_result | ||
set form_result = replace(form_result::text, '"gwp": 265', '"gwp": 298')::jsonb | ||
where application_id in ( | ||
select application_id | ||
from ggircs_portal.application_revision ar | ||
join ggircs_portal.application a | ||
on a.id = ar.application_id | ||
and a.reporting_year = 2022 | ||
and ar.created_at < '2023-05-30' and ar.created_at > '2023-04-01' | ||
) | ||
and form_id=2; | ||
-- SF6 | ||
update ggircs_portal.form_result | ||
set form_result = replace(form_result::text, '"gwp": 23500', '"gwp": 22800')::jsonb | ||
where application_id in ( | ||
select application_id | ||
from ggircs_portal.application_revision ar | ||
join ggircs_portal.application a | ||
on a.id = ar.application_id | ||
and a.reporting_year = 2022 | ||
and ar.created_at < '2023-05-30' and ar.created_at > '2023-04-01' | ||
) | ||
and form_id=2; | ||
-- CF4 | ||
update ggircs_portal.form_result | ||
set form_result = replace(form_result::text, '"gwp": 6630', '"gwp": 7390')::jsonb | ||
where application_id in ( | ||
select application_id | ||
from ggircs_portal.application_revision ar | ||
join ggircs_portal.application a | ||
on a.id = ar.application_id | ||
and a.reporting_year = 2022 | ||
and ar.created_at < '2023-05-30' and ar.created_at > '2023-04-01' | ||
) | ||
and form_id=2; | ||
-- C2F6 | ||
update ggircs_portal.form_result | ||
set form_result = replace(form_result::text, '"gwp": 11100', '"gwp": 12200')::jsonb | ||
where application_id in ( | ||
select application_id | ||
from ggircs_portal.application_revision ar | ||
join ggircs_portal.application a | ||
on a.id = ar.application_id | ||
and a.reporting_year = 2022 | ||
and ar.created_at < '2023-05-30' and ar.created_at > '2023-04-01' | ||
) | ||
and form_id=2; | ||
-- CH2F2 | ||
update ggircs_portal.form_result | ||
set form_result = replace(form_result::text, '"gwp": 677', '"gwp": 675')::jsonb | ||
where application_id in ( | ||
select application_id | ||
from ggircs_portal.application_revision ar | ||
join ggircs_portal.application a | ||
on a.id = ar.application_id | ||
and a.reporting_year = 2022 | ||
and ar.created_at < '2023-05-30' and ar.created_at > '2023-04-01' | ||
) | ||
and form_id=2; | ||
-- CH2HF5 | ||
update ggircs_portal.form_result | ||
set form_result = replace(form_result::text, '"gwp": 3170', '"gwp": 3500')::jsonb | ||
where application_id in ( | ||
select application_id | ||
from ggircs_portal.application_revision ar | ||
join ggircs_portal.application a | ||
on a.id = ar.application_id | ||
and a.reporting_year = 2022 | ||
and ar.created_at < '2023-05-30' and ar.created_at > '2023-04-01' | ||
) | ||
and form_id=2; | ||
-- C2H2F4 | ||
update ggircs_portal.form_result | ||
set form_result = replace(form_result::text, '"gwp": 1300', '"gwp": 1430')::jsonb | ||
where application_id in ( | ||
select application_id | ||
from ggircs_portal.application_revision ar | ||
join ggircs_portal.application a | ||
on a.id = ar.application_id | ||
and a.reporting_year = 2022 | ||
and ar.created_at < '2023-05-30' and ar.created_at > '2023-04-01' | ||
) | ||
and form_id=2; | ||
|
||
alter table ggircs_portal.form_result enable trigger _100_timestamps, enable trigger _immutable_form_result; | ||
|
||
commit; |
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,7 @@ | ||
-- Revert ggircs-portal:database_functions/correct_gwp_values from pg | ||
|
||
begin; | ||
|
||
drop function ggircs_portal_private.correct_gwp_values; | ||
|
||
commit; |
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
Oops, something went wrong.