-
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.
feat: add emission_category_missing_fuel validation function
- Loading branch information
Showing
4 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
schema/deploy/application_validation_functions/emission_category_missing_fuel.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,30 @@ | ||
-- Deploy ggircs-portal:application_validation_functions/emission_category_missing_fuel to pg | ||
-- requires: tables/application_revision_validation_function | ||
-- requires: computed_columns/application_revision_validation | ||
|
||
begin; | ||
|
||
create or replace function ggircs_portal.emission_category_missing_fuel(app_revision ggircs_portal.application_revision) | ||
returns boolean | ||
as $$ | ||
|
||
with x as ( | ||
select distinct(source_type_name) as reported_via_emission | ||
from ggircs_portal.ciip_emission ce | ||
where ce.application_id = app_revision.application_id | ||
and ce.version_number = app_revision.version_number | ||
and ce.annual_co2e > 0 | ||
), y as ( | ||
select distinct (display_name) as reported_via_fuel from ggircs_portal.emission_category ec | ||
join ggircs_portal.ciip_fuel cf | ||
on cf.emission_category_id = ec.id | ||
and cf.application_id = app_revision.application_id | ||
and cf.version_number = app_revision.version_number | ||
and cf.quantity > 0 | ||
) select (select count(*) from x where reported_via_emission not in (select reported_via_fuel from y)) = 0; | ||
|
||
$$ language sql stable; | ||
|
||
comment on function ggircs_portal.emission_category_missing_fuel(ggircs_portal.application_revision) is 'This validation function for a CIIP (CleanBC Industrial Incentive Program) determines if any emission categories have emissions reported in a category, but no corresponding fuels reported for the category'; | ||
|
||
commit; |
7 changes: 7 additions & 0 deletions
7
schema/revert/application_validation_functions/emission_category_missing_fuel.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,7 @@ | ||
-- Revert ggircs-portal:application_validation_functions/emission_category_missing_fuel from pg | ||
|
||
begin; | ||
|
||
drop function ggircs_portal.emission_category_missing_fuel; | ||
|
||
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
7 changes: 7 additions & 0 deletions
7
schema/verify/application_validation_functions/emission_category_missing_fuel.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,7 @@ | ||
-- Verify ggircs-portal:application_validation_functions/emission_category_missing_fuel on pg | ||
|
||
begin; | ||
|
||
select pg_get_functiondef('ggircs_portal.application_revision_ciip_incentive(ggircs_portal.application_revision)'::regprocedure); | ||
|
||
rollback; |