forked from Aidbox/aidbox-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_migrations.py
More file actions
58 lines (52 loc) · 1.42 KB
/
db_migrations.py
File metadata and controls
58 lines (52 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
sdk_migrations = [
{
"id": "20190909_add_drop_before",
"sql": """
DROP FUNCTION IF EXISTS drop_before_all(integer);
CREATE FUNCTION drop_before_all(integer) RETURNS VOID AS $$
declare
e record;
BEGIN
FOR e IN (select LOWER(entity.id) as t_name from entity where resource#>>'{type}' = 'resource' and id != 'OperationOutcome') LOOP
EXECUTE 'delete from "' || e.t_name || '" where txid > ' || $1 ;
END LOOP;
END;
$$ LANGUAGE plpgsql;""",
},
{
"id": "20240913_change_drop_before_all",
"sql": """
DROP FUNCTION IF EXISTS drop_before_all(integer);
CREATE FUNCTION drop_before_all(integer) RETURNS VOID AS $$
declare
e record;
BEGIN
FOR e IN (
SELECT table_name
FROM information_schema.columns
WHERE column_name = 'txid' AND table_schema = 'public' AND table_name NOT LIKE '%_history'
) LOOP
EXECUTE 'DELETE FROM "' || e.table_name || '" WHERE txid > ' || $1 ;
END LOOP;
END;
$$ LANGUAGE plpgsql;""",
},
{
"id": "20251209_fix_drop_before_all_history",
"sql": """
DROP FUNCTION IF EXISTS drop_before_all(integer);
CREATE FUNCTION drop_before_all(integer) RETURNS VOID AS $$
declare
e record;
BEGIN
FOR e IN (
SELECT table_name
FROM information_schema.columns
WHERE column_name = 'txid' AND table_schema = 'public' AND table_name !~ '_history$'
) LOOP
EXECUTE 'DELETE FROM "' || e.table_name || '" WHERE txid > ' || $1 ;
END LOOP;
END;
$$ LANGUAGE plpgsql;""",
},
]