-
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: remove form_result_status insert from trigger
- Loading branch information
Showing
6 changed files
with
132 additions
and
8 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
61 changes: 61 additions & 0 deletions
61
schema/deploy/trigger_functions/checksum_form_results@v1.16.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,61 @@ | ||
-- Deploy ggircs-portal:trigger_functions/checksum_form_results to pg | ||
-- requires: tables/form_result | ||
|
||
begin; | ||
|
||
create or replace function ggircs_portal_private.checksum_form_results() | ||
returns trigger as $$ | ||
declare | ||
new_form_result_hash text; | ||
old_form_result_hash text; | ||
temp_row record; | ||
|
||
begin | ||
|
||
if new.version_number > 1 then | ||
|
||
for temp_row in | ||
select form_id from ggircs_portal.ciip_application_wizard | ||
loop | ||
|
||
new_form_result_hash := (select md5((select form_result::text from ggircs_portal.form_result fr | ||
where fr.application_id = new.application_id | ||
and fr.form_id = temp_row.form_id | ||
and fr.version_number = new.version_number))); | ||
|
||
old_form_result_hash := (select md5((select form_result::text from ggircs_portal.form_result fr | ||
where fr.application_id = new.application_id | ||
and fr.form_id = temp_row.form_id | ||
and fr.version_number = new.version_number - 1))); | ||
|
||
if new_form_result_hash != old_form_result_hash then | ||
insert into ggircs_portal.form_result_status(application_id, form_id, form_result_status) | ||
values (new.application_id, temp_row.form_id, 'needs attention'); | ||
end if; | ||
|
||
end loop; | ||
end if; | ||
|
||
return new; | ||
end; | ||
$$ language plpgsql volatile; | ||
|
||
grant execute on function ggircs_portal_private.checksum_form_results to ciip_administrator, ciip_analyst, ciip_industry_user; | ||
|
||
comment on function ggircs_portal_private.checksum_form_results() | ||
is $$ | ||
a trigger to checksum the form_result columns from the current and previous versions of an application | ||
when the application_revision_status changes. | ||
example usage: | ||
|
||
create table some_schema.some_table ( | ||
... | ||
application_revision_status jsonb | ||
); | ||
create trigger _checksum_form_results | ||
before update of application_revision_status on some_schema.some_table | ||
for each row | ||
execute procedure ggircs_portal_private.checksum_form_results(); | ||
$$; | ||
|
||
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 |
---|---|---|
@@ -1,7 +1,61 @@ | ||
-- Revert ggircs-portal:trigger_functions/checksum_form_results from pg | ||
-- Deploy ggircs-portal:trigger_functions/checksum_form_results to pg | ||
-- requires: tables/form_result | ||
|
||
begin; | ||
|
||
drop function ggircs_portal_private.checksum_form_results; | ||
create or replace function ggircs_portal_private.checksum_form_results() | ||
returns trigger as $$ | ||
declare | ||
new_form_result_hash text; | ||
old_form_result_hash text; | ||
temp_row record; | ||
|
||
begin | ||
|
||
if new.version_number > 1 then | ||
|
||
for temp_row in | ||
select form_id from ggircs_portal.ciip_application_wizard | ||
loop | ||
|
||
new_form_result_hash := (select md5((select form_result::text from ggircs_portal.form_result fr | ||
where fr.application_id = new.application_id | ||
and fr.form_id = temp_row.form_id | ||
and fr.version_number = new.version_number))); | ||
|
||
old_form_result_hash := (select md5((select form_result::text from ggircs_portal.form_result fr | ||
where fr.application_id = new.application_id | ||
and fr.form_id = temp_row.form_id | ||
and fr.version_number = new.version_number - 1))); | ||
|
||
if new_form_result_hash != old_form_result_hash then | ||
insert into ggircs_portal.form_result_status(application_id, form_id, form_result_status) | ||
values (new.application_id, temp_row.form_id, 'needs attention'); | ||
end if; | ||
|
||
end loop; | ||
end if; | ||
|
||
return new; | ||
end; | ||
$$ language plpgsql volatile; | ||
|
||
grant execute on function ggircs_portal_private.checksum_form_results to ciip_administrator, ciip_analyst, ciip_industry_user; | ||
|
||
comment on function ggircs_portal_private.checksum_form_results() | ||
is $$ | ||
a trigger to checksum the form_result columns from the current and previous versions of an application | ||
when the application_revision_status changes. | ||
example usage: | ||
|
||
create table some_schema.some_table ( | ||
... | ||
application_revision_status jsonb | ||
); | ||
create trigger _checksum_form_results | ||
before update of application_revision_status on some_schema.some_table | ||
for each row | ||
execute procedure ggircs_portal_private.checksum_form_results(); | ||
$$; | ||
|
||
commit; |
7 changes: 7 additions & 0 deletions
7
schema/revert/trigger_functions/checksum_form_results@v1.16.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 @@ | ||
-- Revert ggircs-portal:trigger_functions/checksum_form_results from pg | ||
|
||
begin; | ||
|
||
drop function ggircs_portal_private.checksum_form_results; | ||
|
||
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/checksum_form_results@v1.16.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/checksum_form_results on pg | ||
|
||
begin; | ||
|
||
select pg_get_functiondef('ggircs_portal_private.checksum_form_results()'::regprocedure); | ||
|
||
rollback; |