-
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: rewrite has_swrs_report function to check current reporting yea…
…r instead of taking it as a param
- Loading branch information
Showing
4 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
schema/deploy/computed_columns/facility_has_swrs_report_001.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,24 @@ | ||
-- Deploy ggircs-portal:computed_columns/facility_has_swrs_report_001 to pg | ||
-- requires: function_opened_reporting_year | ||
|
||
begin; | ||
|
||
drop function ggircs_portal.facility_has_swrs_report; | ||
|
||
create or replace function ggircs_portal.facility_has_swrs_report(facility ggircs_portal.facility) | ||
returns boolean | ||
as | ||
$function$ | ||
declare | ||
current_year int; | ||
begin | ||
current_year = (select reporting_year from ggircs_portal.opened_reporting_year()); | ||
return (select count(*) from ggircs_portal.get_swrs_facility_data(facility.swrs_facility_id, current_year) where report_id is not null); | ||
end; | ||
|
||
$function$ | ||
language 'plpgsql' stable; | ||
|
||
grant execute on function ggircs_portal.facility_has_swrs_report to ciip_administrator, ciip_analyst, ciip_industry_user; | ||
|
||
commit; |
21 changes: 21 additions & 0 deletions
21
schema/revert/computed_columns/facility_has_swrs_report_001.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,21 @@ | ||
-- Revert ggircs-portal:computed_columns/facility_has_swrs_report_001 from pg | ||
|
||
begin; | ||
|
||
drop function ggircs_portal.facility_has_swrs_report; | ||
|
||
create or replace function ggircs_portal.facility_has_swrs_report(facility ggircs_portal.facility, reporting_year integer) | ||
returns boolean | ||
as | ||
$function$ | ||
declare | ||
begin | ||
return (select count(*) from ggircs_portal.get_swrs_facility_data(facility.swrs_facility_id, reporting_year) where report_id is not null); | ||
end; | ||
|
||
$function$ | ||
language 'plpgsql' stable; | ||
|
||
grant execute on function ggircs_portal.facility_has_swrs_report to ciip_administrator, ciip_analyst, ciip_industry_user; | ||
|
||
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/computed_columns/facility_has_swrs_report_001.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:computed_columns/facility_has_swrs_report_001 on pg | ||
|
||
begin; | ||
|
||
select pg_get_functiondef('ggircs_portal.facility_has_swrs_report(ggircs_portal.facility)'::regprocedure); | ||
|
||
rollback; |