-
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 trigger_function to create/refresh review_step
- Loading branch information
Showing
4 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
schema/deploy/trigger_functions/create_or_refresh_review_step.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,47 @@ | ||
-- Deploy ggircs-portal:trigger_functions/create_or_refresh_review_step to pg | ||
-- requires: tables/review_step | ||
|
||
begin; | ||
|
||
create or replace function ggircs_portal_private.create_or_refresh_review_step() | ||
returns trigger as $$ | ||
|
||
declare | ||
temp_row record; | ||
|
||
begin | ||
|
||
for temp_row in | ||
select id, step_name from ggircs_portal.review_step_name where is_active = true | ||
loop | ||
if exists(select * from ggircs_portal.review_step where application_id = new.application_id and review_step_name_id = temp_row.id) then | ||
update ggircs_portal.review_step set is_complete = false where application_id = new.application_id and review_step_name_id = temp_row.id; | ||
else | ||
insert into ggircs_portal.review_step(application_id, review_step_name_id) | ||
values (new.application_id, temp_row.id); | ||
end if; | ||
end loop; | ||
|
||
return new; | ||
end; | ||
$$ language plpgsql volatile; | ||
|
||
grant execute on function ggircs_portal_private.create_or_refresh_review_step to ciip_administrator, ciip_analyst, ciip_industry_user; | ||
|
||
comment on function ggircs_portal_private.create_or_refresh_review_step() | ||
is $$ | ||
a trigger to create a review step for an application if it does not exist else reset the is_complete value to false | ||
when the application_revision_status changes to submitted. | ||
example usage: | ||
|
||
create table some_schema.some_table ( | ||
... | ||
application_revision_status ggircs_portal.application_revision_status | ||
); | ||
create trigger _create_or_refresh_review_step | ||
before insert of application_revision_status on some_schema.some_table | ||
for each row | ||
execute procedure ggircs_portal_private.create_or_refresh_review_step(); | ||
$$; | ||
|
||
commit; |
7 changes: 7 additions & 0 deletions
7
schema/revert/trigger_functions/create_or_refresh_review_step.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:trigger_functions/create_or_refresh_review_step from pg | ||
|
||
begin; | ||
|
||
drop function ggircs_portal_private.create_or_refresh_review_step; | ||
|
||
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/create_or_refresh_review_step.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/create_or_refresh_review_step on pg | ||
|
||
begin; | ||
|
||
select pg_get_functiondef('ggircs_portal_private.create_or_refresh_review_step()'::regprocedure); | ||
|
||
rollback; |