Skip to content

Commit 4b73b94

Browse files
committed
Restore ability to run upgrades as non-super user
Fixes ledgersmb#9381
1 parent 69fe9cc commit 4b73b94

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

sql/changes/1.12/reconciliation-workflow.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ create function pg_temp.new_workflow(approved boolean, submitted boolean,
2222
$$ language sql;
2323

2424

25-
SET session_replication_role = replica; -- disable triggers
25+
alter table cr_report disable trigger all;
2626
update cr_report
2727
set workflow_id = pg_temp.new_workflow(approved, submitted, deleted);
28-
SET session_replication_role = DEFAULT; -- re-enable triggers
28+
alter table cr_report enable trigger all;
2929

3030

3131
insert into
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
alter table cr_report
3+
add column workflow_id bigint references workflow(workflow_id);
4+
5+
-- now fill the workflow_ids
6+
create function pg_temp.new_workflow(approved boolean, submitted boolean,
7+
deleted boolean)
8+
returns int
9+
as $$
10+
11+
insert into workflow (workflow_id, type, state, last_update)
12+
values (nextval('workflow_seq'),
13+
'reconciliation',
14+
case
15+
when deleted then 'DELETED'
16+
when approved then 'APPROVED'
17+
when submitted then 'SUBMITTED'
18+
else 'SAVED'
19+
end,
20+
NOW())
21+
returning workflow_id;
22+
$$ language sql;
23+
24+
25+
SET session_replication_role = replica; -- disable triggers
26+
update cr_report
27+
set workflow_id = pg_temp.new_workflow(approved, submitted, deleted);
28+
SET session_replication_role = DEFAULT; -- re-enable triggers
29+
30+
31+
insert into
32+
workflow_history (
33+
workflow_hist_id, workflow_id, action, description, state,
34+
workflow_user, history_date)
35+
select nextval('workflow_history_seq'), workflow_id, 'migrate',
36+
'Workflow created by migration', state,
37+
CURRENT_USER, NOW()
38+
from cr_report
39+
join workflow using (workflow_id);
40+
41+
alter table cr_report
42+
alter column workflow_id set not null;

0 commit comments

Comments
 (0)