Skip to content

Commit 8f6d517

Browse files
committed
chore: handle the new commit_form_change_internal args in commit_form_change
1 parent 6932712 commit 8f6d517

File tree

7 files changed

+65
-6
lines changed

7 files changed

+65
-6
lines changed

schema/deploy/mutations/commit_form_change.sql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ begin
1212
validation_errors = coalesce(form_change_patch.validation_errors, validation_errors)
1313
where id=row_id;
1414

15-
return (select cif_private.commit_form_change_internal((select row(form_change.*)::cif.form_change from cif.form_change where id = row_id)));
15+
return (select cif_private.commit_form_change_internal(
16+
(select row(form_change.*)::cif.form_change from cif.form_change where id = row_id),
17+
(select id from cif.project_revision
18+
where project_id=(select project_id from cif.project_revision where id = form_change_patch.project_revision_id)
19+
and change_status = 'pending' and id != form_change_patch.project_revision_id limit 1)
20+
));
1621
end;
1722
$$ language plpgsql volatile;
1823

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- Deploy cif:mutations/commit_form_change to pg
2+
-- requires: tables/form_change
3+
4+
begin;
5+
6+
create or replace function cif.commit_form_change(row_id int, form_change_patch cif.form_change)
7+
returns cif.form_change as $$
8+
begin
9+
10+
update cif.form_change set
11+
new_form_data = coalesce(form_change_patch.new_form_data, new_form_data),
12+
validation_errors = coalesce(form_change_patch.validation_errors, validation_errors)
13+
where id=row_id;
14+
15+
return (select cif_private.commit_form_change_internal((select row(form_change.*)::cif.form_change from cif.form_change where id = row_id)));
16+
end;
17+
$$ language plpgsql volatile;
18+
19+
grant execute on function cif.commit_form_change to cif_internal, cif_external, cif_admin;
20+
21+
comment on function cif.commit_form_change is 'Custom mutation to commit a form_change record via the API. Only used for records that are independent of a project such as the lists of contacts and operators.';
22+
23+
commit;
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
1-
-- Revert cif:mutations/commit_form_change from pg
1+
-- Deploy cif:mutations/commit_form_change to pg
2+
-- requires: tables/form_change
23

34
begin;
45

5-
drop function cif.commit_form_change;
6+
create or replace function cif.commit_form_change(row_id int, form_change_patch cif.form_change)
7+
returns cif.form_change as $$
8+
begin
9+
10+
update cif.form_change set
11+
new_form_data = coalesce(form_change_patch.new_form_data, new_form_data),
12+
validation_errors = coalesce(form_change_patch.validation_errors, validation_errors)
13+
where id=row_id;
14+
15+
return (select cif_private.commit_form_change_internal((select row(form_change.*)::cif.form_change from cif.form_change where id = row_id)));
16+
end;
17+
$$ language plpgsql volatile;
18+
19+
grant execute on function cif.commit_form_change to cif_internal, cif_external, cif_admin;
20+
21+
comment on function cif.commit_form_change is 'Custom mutation to commit a form_change record via the API. Only used for records that are independent of a project such as the lists of contacts and operators.';
622

723
commit;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- Revert cif:mutations/commit_form_change from pg
2+
3+
begin;
4+
5+
drop function cif.commit_form_change;
6+
7+
commit;

schema/sqitch.plan

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,4 @@ functions/handle_milestone_form_change_commit [functions/handle_milestone_form_c
368368
functions/jsonb_minus 2023-10-30T19:55:55Z Mike Vesprini <mike@button.is> # Function to provide the object difference between two jsonb objects
369369
mutations/commit_form_change_internal [mutations/commit_form_change_internal@1.15.0] 2023-10-30T21:34:15Z Mike Vesprini <mike@button.is> # Handle rebasing when committing with another pending revision on the same project"
370370
mutations/commit_project_revision [mutations/commit_project_revision@1.15.0] 2023-10-31T00:07:01Z Mike Vesprini <mike@button.is> # Update function to pass new parameters to commit_form_change_internal
371+
mutations/commit_form_change [mutations/commit_form_change@1.15.0] 2023-11-22T19:00:00Z Mike Vesprini <mike@button.is> # Add pending project revision id to args of commit_form_change_internal call

schema/test/unit/mutations/commit_form_change_test.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ select plan(2);
77
/** SETUP **/
88
truncate cif.form_change restart identity;
99

10-
create or replace function cif_private.commit_form_change_internal(fc cif.form_change)
10+
create or replace function cif_private.commit_form_change_internal(fc cif.form_change, pending_project_revision_id int default null)
1111
returns cif.form_change as $$
1212
begin
1313
return fc;
@@ -54,7 +54,7 @@ select results_eq(
5454
validation_errors
5555
from cif.commit_form_change(
5656
12345,
57-
(select row( null, '{"updated":true}', null, null, null, null, null, null, null, '["hazErrors"]', null, null, null, null, null)::cif.form_change)
57+
(select row( null, '{"updated":true}', null, null, null, null, null, null, null, '[]', null, null, null, null, null)::cif.form_change)
5858
);
5959
$$,
6060
$$
@@ -68,7 +68,7 @@ select results_eq(
6868
null::int,
6969
'pending'::varchar,
7070
'reporting_requirement'::varchar,
71-
'["hazErrors"]'::jsonb
71+
'[]'::jsonb
7272
)
7373
$$,
7474
'commit_form_change calls the private commit_form_change_internal() function'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- Verify cif:mutations/commit_form_change on pg
2+
3+
begin;
4+
5+
select pg_get_functiondef('cif.commit_form_change(int, cif.form_change)'::regprocedure);
6+
7+
rollback;

0 commit comments

Comments
 (0)