Skip to content

Commit

Permalink
chore: add electricity_amount column to emission table for EIO emissions
Browse files Browse the repository at this point in the history
  • Loading branch information
dleard committed Oct 17, 2023
1 parent b05adc3 commit 67ee425
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
10 changes: 10 additions & 0 deletions deploy/swrs/public/table/emission_004.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- Deploy ggircs:swrs/public/table/emission_004 to pg
-- requires: swrs/public/table/emission_003

begin;

alter table swrs.emission add electricity_amount numeric;

comment on column swrs.emission.electricity_amount is 'The amount of electricity imported/exported for the row data';

commit;
9 changes: 4 additions & 5 deletions deploy/swrs/transform/materialized_view/eio_emission.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ create materialized view swrs_transform.eio_emission as (
substance_idx integer path 'string(count(./ancestor::Substance/preceding-sibling::Substance))' not null,
fuel_idx integer path 'string(count(./ancestor::Fuel/preceding-sibling::Fuel))' not null,
fuel_name varchar(1000) path 'name((./ancestor::Emissions/parent::*[not(name() = "Substance")][not(name() = "Substances")] | ./parent::*[not(name() = "EIOEmissions")])[1])' not null, -- eccc_xml_file_id=2514
emissions_idx integer path 'string(count(./ancestor::Emissions/preceding-sibling::Emissions))' not null,
emission_idx integer path 'string(count(./preceding-sibling::Emission))' not null,
emissions_idx integer path 'string(count(./ancestor::Emissions/preceding-sibling::EIOEmissions))' not null,
emission_idx integer path 'string(count(./preceding-sibling::EIOEmission))' not null,
emission_type varchar(1000) path '../@EmissionsType[normalize-space(.)]',
gas_type varchar(1000) path 'GasType[normalize-space(.)]',
not_applicable boolean path 'NotApplicable[normalize-space(.)]',
quantity numeric path 'EIOEmissionAmount[normalize-space(.)]' default 0,
calculated_quantity numeric path 'EIOEmissionAmount[normalize-space(.)]' default 0,
electricity_amount numeric path 'EIOElectricityAmount[normalize-space(.)]' default 0,
electricity_amount numeric path 'EIOElectricityAmount[normalize-space(.)]' default 0
) as emission_details
order by eccc_xml_file_id
) with no data;
Expand Down Expand Up @@ -61,11 +61,10 @@ comment on column swrs_transform.eio_emission.emissions_idx is 'The number of pr
comment on column swrs_transform.eio_emission.emission_idx is 'The number of preceding Emission siblings before this emission';
comment on column swrs_transform.eio_emission.emission_type is 'The type of the emission';
comment on column swrs_transform.eio_emission.gas_type is 'The type of the gas';
comment on column swrs_transform.eio_emission.methodology is 'The emission methodology';
comment on column swrs_transform.eio_emission.not_applicable is 'Is the emission applicable/NA';
comment on column swrs_transform.eio_emission.quantity is 'The quantity of the emission';
comment on column swrs_transform.eio_emission.calculated_quantity is 'The CO2 Equivalent quantity of the emission';
comment on column swrs_transform.eio_emission.emission_category is 'The emissions category';
comment on column swrs_transform.eio_emission.electricity_amount is 'The amount of electricity imported or exported';


commit;
7 changes: 7 additions & 0 deletions revert/swrs/public/table/emission_004.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Revert ggircs:swrs/public/table/emission_004 from pg

begin;

alter table swrs.emission drop column electricity_amount;

commit;
1 change: 1 addition & 0 deletions sqitch.plan
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ swrs/parameters/table/gwp 2023-06-05T22:35:23Z Brianna Cerkiewicz <briannacerkie
swrs/public/table/emission_003 2023-06-06T15:37:39Z Brianna Cerkiewicz <briannacerkiewicz@pop-os> # Add ar5_calculated_quantity column to the emissions table
swrs/transform/function/load_emission [swrs/transform/function/[email protected]] 2023-06-06T16:04:44Z Brianna Cerkiewicz <briannacerkiewicz@pop-os> # Calculate the ar5_calculated_quantity column in load_emission
@1.17.0 2023-06-19T18:15:06Z Dylan Leard <[email protected]> # release v1.17.0
swrs/public/table/emission_004 [swrs/public/table/emission_003] 2023-10-16T21:28:21Z Dylan Leard <[email protected]> # Migration: add electricity_amount to emission table for EIO emissions
swrs/transform/materialized_view/eio_emission [swrs/transform/schema] 2023-10-12T21:56:46Z Dylan Leard <[email protected]> # Add a materialized view for EIO Emissions. Necessary due to schema change for EIO Emissions as of reporting year 2022.
swrs/transform/function/load_emission [swrs/transform/function/[email protected]] 2023-10-12T21:42:08Z Dylan Leard <[email protected]> # Migration: include emissions from EIOs after ECCC schema change

7 changes: 7 additions & 0 deletions verify/swrs/public/table/emission_004.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Verify ggircs:swrs/public/table/emission_004 on pg

begin;

select pg_catalog.has_table_privilege('swrs.emission', 'select');

rollback;

0 comments on commit 67ee425

Please sign in to comment.