-
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.
fix: only fire trigger on change from draft to submitted
- Loading branch information
Showing
6 changed files
with
60 additions
and
2 deletions.
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
24 changes: 24 additions & 0 deletions
24
schema/deploy/trigger_functions/ensure_window_open_submit_application_status@v2.6.0.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:trigger_functions/ensure_window_open_submit_application_status to pg | ||
|
||
begin; | ||
|
||
create or replace function ggircs_portal_private.ensure_window_open_submit_application_status() | ||
returns trigger as $$ | ||
begin | ||
if (select reporting_year from ggircs_portal.opened_reporting_year()) is null and new.version_number = 1 then | ||
if (new.application_revision_status = 'submitted') then | ||
raise exception 'You cannot submit an application when the application window is closed'; | ||
end if; | ||
if (new.application_revision_status = 'draft') then | ||
raise exception 'You cannot start a draft when the application window is closed'; | ||
end if; | ||
end if; | ||
return new; | ||
end; | ||
$$ language plpgsql; | ||
|
||
grant execute on function ggircs_portal_private.ensure_window_open_submit_application_status to ciip_administrator, ciip_analyst, ciip_industry_user; | ||
|
||
comment on function ggircs_portal_private.ensure_window_open_submit_application_status is 'a trigger function that throws an exception if the application window is not opened, the application version number is <= 1, and the new status is either "draft" or "submitted"'; | ||
|
||
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
24 changes: 24 additions & 0 deletions
24
schema/revert/trigger_functions/ensure_window_open_submit_application_status@v2.6.0.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:trigger_functions/ensure_window_open_submit_application_status to pg | ||
|
||
begin; | ||
|
||
create or replace function ggircs_portal_private.ensure_window_open_submit_application_status() | ||
returns trigger as $$ | ||
begin | ||
if (select reporting_year from ggircs_portal.opened_reporting_year()) is null and new.version_number <= 1 then | ||
if (new.application_revision_status = 'submitted') then | ||
raise exception 'You cannot submit an application when the application window is closed'; | ||
end if; | ||
if (new.application_revision_status = 'draft') then | ||
raise exception 'You cannot start a draft when the application window is closed'; | ||
end if; | ||
end if; | ||
return new; | ||
end; | ||
$$ language plpgsql; | ||
|
||
grant execute on function ggircs_portal_private.ensure_window_open_submit_application_status to ciip_administrator, ciip_analyst, ciip_industry_user; | ||
|
||
comment on function ggircs_portal_private.ensure_window_open_submit_application_status is 'a trigger function that throws an exception if the application window is not opened, the application version number is <= 1, and the new status is either "draft" or "submitted"'; | ||
|
||
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/trigger_functions/ensure_window_open_submit_application_status@v2.6.0.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:trigger_functions/ensure_window_open_submit_application_status on pg | ||
|
||
begin; | ||
|
||
select pg_get_functiondef('ggircs_portal_private.ensure_window_open_submit_application_status()'::regprocedure); | ||
|
||
rollback; |