Skip to content

Commit 634dbf7

Browse files
committed
Fix Pg13 compatibility for old migrations during upgrade
Older versions of Pg don't accept a complex expression in EXECUTE ... INTO. Instead, the expression must be a single variable name.
1 parent 2027436 commit 634dbf7

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

sql/changes/1.13/old-migration-schemas-cleanup.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ create or replace function pg_temp.schedule_schema_deletion(in_schema text)
44
declare
55
t_transdate date;
66
t_cleanup_date date;
7+
t_query text;
78
begin
89
perform *
910
from information_schema.schemata
@@ -13,7 +14,8 @@ begin
1314
return;
1415
end if;
1516

16-
execute 'select max(transdate) from ' || quote_ident(in_schema) || '.acc_trans' into t_transdate;
17+
t_query := 'select max(transdate) from ' || quote_ident(in_schema) || '.acc_trans';
18+
execute t_query into t_transdate;
1719
t_cleanup_date := greatest(
1820
coalesce((t_transdate + '7 years'::interval), CURRENT_DATE),
1921
(CURRENT_DATE + '2 years'::interval)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
create or replace function pg_temp.schedule_schema_deletion(in_schema text)
3+
returns void as $$
4+
declare
5+
t_transdate date;
6+
t_cleanup_date date;
7+
begin
8+
perform *
9+
from information_schema.schemata
10+
where schema_name = in_schema;
11+
12+
if not found then
13+
return;
14+
end if;
15+
16+
execute 'select max(transdate) from ' || quote_ident(in_schema) || '.acc_trans' into t_transdate;
17+
t_cleanup_date := greatest(
18+
coalesce((t_transdate + '7 years'::interval), CURRENT_DATE),
19+
(CURRENT_DATE + '2 years'::interval)
20+
);
21+
insert into defaults (setting_key, "value")
22+
values ('post-upgrade-run:cleanup-migration-schema/' || in_schema,
23+
json_build_object('action', 'cleanup-migration-schema',
24+
'description', 'Cleanup of migration schema "' || in_schema || '"',
25+
'run-after', t_cleanup_date::text,
26+
'args', json_build_object('schema', in_schema)::text));
27+
28+
return;
29+
end;
30+
$$ language plpgsql;
31+
32+
DO $$
33+
BEGIN
34+
perform pg_temp.schedule_schema_deletion('lsmb12');
35+
perform pg_temp.schedule_schema_deletion('lsmb13');
36+
perform pg_temp.schedule_schema_deletion('sl28');
37+
perform pg_temp.schedule_schema_deletion('sl30');
38+
perform pg_temp.schedule_schema_deletion('sl32');
39+
END;
40+
$$ LANGUAGE plpgsql;

0 commit comments

Comments
 (0)