Skip to content

Commit 2448315

Browse files
chore: Deprecate old analytics resource tables (#24210)
1 parent f52eefa commit 2448315

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
-- It relates to https://dhis2.atlassian.net/browse/DHIS2-21273
2+
-- Rename/deprecated old analytics resource tables, so it fails fast if someone is still pointing to them.
3+
4+
do $$
5+
declare
6+
tbl text;
7+
new_name text;
8+
begin
9+
for tbl in
10+
-- List of possible analytics resource tables.
11+
select unnest(array[
12+
'_categoryoptioncomboname',
13+
'_categorystructure',
14+
'_dataelementcategoryoptioncombo',
15+
'_dataelementgroupsetstructure',
16+
'_dataelementstructure',
17+
'_datasetorganisationunitcategory',
18+
'_dateperiodstructure',
19+
'_indicatorgroupsetstructure',
20+
'_organisationunitgroupsetstructure',
21+
'_orgunitstructure',
22+
'_periodstructure',
23+
'_relationship'
24+
])
25+
loop
26+
-- Build the new name by replacing the leading underscore with "_deprecated".
27+
new_name := '_deprecated_' || substr(tbl, 2);
28+
29+
-- Only rename/deprecate if the table actually exists.
30+
if exists (
31+
select 1
32+
from pg_tables
33+
where schemaname = 'public'
34+
and tablename = tbl
35+
) then
36+
execute format('alter table public.%I rename to %I;', tbl, new_name);
37+
end if;
38+
end loop;
39+
end $$;

0 commit comments

Comments
 (0)