-
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 function to protect date ranges in reporting_year table
- Loading branch information
Showing
4 changed files
with
47 additions
and
1 deletion.
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,31 @@ | ||
-- Deploy ggircs-portal:trigger_functions/protect_date_overlap to pg | ||
-- requires: schema_ggircs_portal_private | ||
|
||
begin; | ||
create or replace function ggircs_portal_private.protect_date_overlap() | ||
returns trigger as $$ | ||
declare | ||
temp_row record; | ||
|
||
begin | ||
|
||
for temp_row in | ||
select * from ggircs_portal.reporting_year | ||
loop | ||
if (new.reporting_year != temp_row.year) then | ||
if ((new.reporting_period_start between temp_row.reporting_period_start and temp_row.reporting_period_end) | ||
or (new.reporting_period_end between temp_row.reporting_period_start and temp_row.reporting_period_end) | ||
or (new.application_open_time between temp_row.application_open_time and temp_row.application_close_time) | ||
or (new.application_close_time between temp_row.application_open_time and temp_row.application_close_time)) then | ||
raise exception 'New date range entry overlaps with date range for reporting year %', temp_row.reporting_year; | ||
end if; | ||
end if; | ||
end loop; | ||
|
||
return new; | ||
end; | ||
$$ language plpgsql volatile; | ||
|
||
comment on function ggircs_portal_private.protect_date_overlap is 'Trigger function excepts if a date range in reporting_year overlaps with another row'; | ||
|
||
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:trigger_functions/protect_date_overlap from pg | ||
|
||
begin; | ||
|
||
drop function ggircs_portal_private.protect_date_overlap; | ||
|
||
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
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:trigger_functions/protect_date_overlap on pg | ||
|
||
begin; | ||
|
||
select pg_get_functiondef('ggircs_portal_private.protect_date_overlap()'::regprocedure); | ||
|
||
rollback; |
💥