From 188f6e6260e96a8356a1f3286d291d2fe7b52092 Mon Sep 17 00:00:00 2001 From: Vadim Laletin Date: Fri, 13 Sep 2024 12:58:08 +0200 Subject: [PATCH] Update drop_before_all to support fhir-schema and old approach. Closes #68 --- CHANGELOG.md | 4 ++++ aidbox_python_sdk/__init__.py | 2 +- aidbox_python_sdk/db_migrations.py | 25 ++++++++++++++++++++++--- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c91a9a4..deca176 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.12 + +- Update drop_before_all to support fhir-schema and old approach #68 + ## 0.1.11 - Add `headers` to SDKOperationRequest diff --git a/aidbox_python_sdk/__init__.py b/aidbox_python_sdk/__init__.py index 9784b3e..3cf56ea 100644 --- a/aidbox_python_sdk/__init__.py +++ b/aidbox_python_sdk/__init__.py @@ -1,5 +1,5 @@ __title__ = "aidbox-python-sdk" -__version__ = "0.1.11" +__version__ = "0.1.12" __author__ = "beda.software" __license__ = "None" __copyright__ = "Copyright 2024 beda.software" diff --git a/aidbox_python_sdk/db_migrations.py b/aidbox_python_sdk/db_migrations.py index 344c8d7..6c389bf 100644 --- a/aidbox_python_sdk/db_migrations.py +++ b/aidbox_python_sdk/db_migrations.py @@ -13,7 +13,26 @@ END LOOP; END; -$$ LANGUAGE plpgsql; - """, - } +$$ 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;""", + }, ]