Skip to content

Commit

Permalink
feat: rewrite has_swrs_report function to check current reporting yea…
Browse files Browse the repository at this point in the history
…r instead of taking it as a param
  • Loading branch information
dleard committed Jun 25, 2020
1 parent 0ee5be5 commit 3022cd4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
24 changes: 24 additions & 0 deletions schema/deploy/computed_columns/facility_has_swrs_report_001.sql
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 schema/revert/computed_columns/facility_has_swrs_report_001.sql
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;
1 change: 1 addition & 0 deletions schema/sqitch.plan
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,4 @@ search_functions/search_all_facilities [search_functions/search_all_facilities@v
search_functions/search_certification_requests [search_functions/search_certification_requests@v1.0.0-rc.5] 2020-06-25T16:09:26Z Dylan Leard <dylan@button.is> # Migration: add guard if clause, fixes failure on null data
policies/facility_policies [policies/facility_policies@v1.0.0-rc.5] 2020-06-25T18:19:13Z Dylan Leard <dylan@button.is> # Migration: add organisation request approved requirement
database_functions/get_valid_applications_for_reporter [database_functions/get_valid_applications_for_reporter@v1.0.0-rc.5] 2020-06-25T18:22:04Z Dylan Leard <dylan@button.is> # Migration: add organisation request approved requirement to rls
computed_columns/facility_has_swrs_report_001 [function_opened_reporting_year] 2020-06-24T20:15:42Z Dylan Leard <dylan@button.is> # Migration: removes reporting_year parameter & retrieves current year via a function
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;

0 comments on commit 3022cd4

Please sign in to comment.