-
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: add trigger to form_result table
fix: syntax errors fix: clean up function
- Loading branch information
1 parent
bfde612
commit 3eb2a1b
Showing
7 changed files
with
74 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- Deploy ggircs-portal:tables/form_result_001 to pg | ||
-- requires: tables/form_result | ||
-- requires: trigger_functions/immutable_form_result | ||
|
||
begin; | ||
|
||
create trigger _immutable_form_result | ||
before insert or update of form_result | ||
on ggircs_portal.form_result | ||
for each row | ||
execute procedure ggircs_portal_private.immutable_form_result(); | ||
|
||
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,28 @@ | ||
-- Deploy ggircs-portal:trigger_functions/immutable-form-result to pg | ||
-- requires: schema_ggircs_portal_private | ||
|
||
begin; | ||
create or replace function ggircs_portal_private.immutable_form_result() | ||
returns trigger as $$ | ||
declare | ||
app_status text; | ||
begin | ||
|
||
select ars.application_revision_status::text into app_status | ||
from ggircs_portal.application_revision_status ars | ||
where ars.application_id = new.application_id | ||
and ars.version_number = new.version_number | ||
and ars.version_number != 0 | ||
order by created_at desc limit 1; | ||
|
||
if (app_status='submitted') then | ||
raise exception 'Form_result is immutable after application has been submitted'; | ||
end if; | ||
|
||
return new; | ||
end; | ||
$$ language plpgsql volatile; | ||
|
||
comment on function ggircs_portal_private.immutable_form_result is 'Trigger function ensures form result is immutable if application has been 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- Revert ggircs-portal:tables/form_result_001 from pg | ||
|
||
begin; | ||
|
||
drop trigger _immutable_form_result on ggircs_portal.form_result; | ||
|
||
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/immutable-form-result from pg | ||
|
||
begin; | ||
|
||
drop function ggircs_portal_private.immutable_form_result; | ||
|
||
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,11 @@ | ||
-- Verify ggircs-portal:tables/form_result_001 on pg | ||
|
||
begin; | ||
|
||
select exists (select tgname | ||
from pg_trigger | ||
where not tgisinternal | ||
and tgrelid = 'ggircs_portal.form_result'::regclass | ||
and tgname = '_immutable_form_result'); | ||
|
||
rollback; |
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/immutable-form-result on pg | ||
|
||
begin; | ||
|
||
select pg_get_functiondef('ggircs_portal_private.immutable_form_result()'::regprocedure); | ||
|
||
rollback; |