From b265e57b4b5f4fbf7e5e7d5a437b837aceb3c295 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Fri, 13 Sep 2024 08:56:27 +0200 Subject: [PATCH] basis.tx_history_txid(), basis.tx_operation, basis.tx_create_historicization(...) --- .../db/changelog/0-basis/030-historization.sql | 18 +++++++++--------- .../6200-hs-booking-project.sql | 2 +- .../630-booking-item/6200-hs-booking-item.sql | 2 +- .../7010-hs-hosting-asset.sql | 2 +- .../rbac/context/ContextBasedTest.java | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/resources/db/changelog/0-basis/030-historization.sql b/src/main/resources/db/changelog/0-basis/030-historization.sql index f5e4eba2..6368df06 100644 --- a/src/main/resources/db/changelog/0-basis/030-historization.sql +++ b/src/main/resources/db/changelog/0-basis/030-historization.sql @@ -3,7 +3,7 @@ -- ============================================================================ --changeset hs-global-historization-tx-history-txid:1 endDelimiter:--// -- ---------------------------------------------------------------------------- -create or replace function tx_history_txid() +create or replace function basis.tx_history_txid() returns xid8 stable language plpgsql as $$ declare @@ -12,18 +12,18 @@ declare historicalTxId xid8; historicalTimestamp timestamp; begin - select coalesce(current_setting('hsadminng.tx_history_txid', true), '') into historicalTxIdSetting; + select coalesce(current_setting('hsadminng.basis.tx_history_txid', true), '') into historicalTxIdSetting; select coalesce(current_setting('hsadminng.tx_history_timestamp', true), '') into historicalTimestampSetting; if historicalTxIdSetting > '' and historicalTimestampSetting > '' then - raise exception 'either hsadminng.tx_history_txid or hsadminng.tx_history_timestamp must be set, but both are set: (%, %)', + raise exception 'either hsadminng.basis.tx_history_txid or hsadminng.tx_history_timestamp must be set, but both are set: (%, %)', historicalTxIdSetting, historicalTimestampSetting; end if; if historicalTxIdSetting = '' and historicalTimestampSetting = '' then - raise exception 'either hsadminng.tx_history_txid or hsadminng.tx_history_timestamp must be set, but both are unset or empty: (%, %)', + raise exception 'either hsadminng.basis.tx_history_txid or hsadminng.tx_history_timestamp must be set, but both are unset or empty: (%, %)', historicalTxIdSetting, historicalTimestampSetting; end if; -- just for debugging / making sure the function is only called once per query - -- raise notice 'tx_history_txid() called with: (%, %)', historicalTxIdSetting, historicalTimestampSetting; + -- raise notice 'basis.tx_history_txid() called with: (%, %)', historicalTxIdSetting, historicalTimestampSetting; if historicalTxIdSetting is null or historicalTxIdSetting = '' then select historicalTimestampSetting::timestamp into historicalTimestamp; @@ -40,7 +40,7 @@ end; $$; --changeset hs-global-historization-tx-historicize-tf:1 endDelimiter:--// -- ---------------------------------------------------------------------------- -create type "tx_operation" as enum ('INSERT', 'UPDATE', 'DELETE', 'TRUNCATE'); +create type basis.tx_operation as enum ('INSERT', 'UPDATE', 'DELETE', 'TRUNCATE'); create or replace function tx_historicize_tf() returns trigger @@ -95,7 +95,7 @@ end; $$; -- ---------------------------------------------------------------------------- -create or replace procedure tx_create_historicization(baseTable varchar) +create or replace procedure basis.tx_create_historicization(baseTable varchar) language plpgsql as $$ declare createHistTableSql varchar; @@ -111,7 +111,7 @@ begin 'CREATE TABLE ' || baseTable || '_ex (' || ' version_id serial PRIMARY KEY,' || ' txid xid8 NOT NULL REFERENCES basis.tx_context(txid),' || - ' trigger_op tx_operation NOT NULL,' || + ' trigger_op basis.tx_operation NOT NULL,' || ' alive boolean not null,' || ' LIKE ' || baseTable || ' EXCLUDING CONSTRAINTS' || @@ -132,7 +132,7 @@ begin 'CREATE OR REPLACE VIEW %1$s AS' || '(' || -- make sure the function is only called once, not for every matching row in basis.tx_context - ' WITH txh AS (SELECT tx_history_txid() AS txid) ' || + ' WITH txh AS (SELECT basis.tx_history_txid() AS txid) ' || ' SELECT %2$s' || ' FROM %3$s' || ' WHERE alive = TRUE' || diff --git a/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6200-hs-booking-project.sql b/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6200-hs-booking-project.sql index 7154fff6..8ea0cc68 100644 --- a/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6200-hs-booking-project.sql +++ b/src/main/resources/db/changelog/6-hs-booking/620-booking-project/6200-hs-booking-project.sql @@ -25,5 +25,5 @@ call basis.create_journal('hs_booking_project'); -- ============================================================================ --changeset hs-booking-project-MAIN-TABLE-HISTORIZATION:1 endDelimiter:--// -- ---------------------------------------------------------------------------- -call tx_create_historicization('hs_booking_project'); +call basis.tx_create_historicization('hs_booking_project'); --// diff --git a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6200-hs-booking-item.sql b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6200-hs-booking-item.sql index 228cd7d7..6cb8808a 100644 --- a/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6200-hs-booking-item.sql +++ b/src/main/resources/db/changelog/6-hs-booking/630-booking-item/6200-hs-booking-item.sql @@ -42,6 +42,6 @@ call basis.create_journal('hs_booking_item'); -- ============================================================================ --changeset hs-booking-item-MAIN-TABLE-HISTORIZATION:1 endDelimiter:--// -- ---------------------------------------------------------------------------- -call tx_create_historicization('hs_booking_item'); +call basis.tx_create_historicization('hs_booking_item'); --// diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql index e791b67c..34a79af5 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql @@ -173,7 +173,7 @@ call basis.create_journal('hs_hosting_asset'); -- ============================================================================ --changeset hs-hosting-asset-MAIN-TABLE-HISTORIZATION:1 endDelimiter:--// -- ---------------------------------------------------------------------------- -call tx_create_historicization('hs_hosting_asset'); +call basis.tx_create_historicization('hs_hosting_asset'); --// diff --git a/src/test/java/net/hostsharing/hsadminng/rbac/context/ContextBasedTest.java b/src/test/java/net/hostsharing/hsadminng/rbac/context/ContextBasedTest.java index 59704ad4..1ba06236 100644 --- a/src/test/java/net/hostsharing/hsadminng/rbac/context/ContextBasedTest.java +++ b/src/test/java/net/hostsharing/hsadminng/rbac/context/ContextBasedTest.java @@ -52,7 +52,7 @@ public abstract class ContextBasedTest { protected void historicalContext(final Long txId) { // set local cannot be used with query parameters em.createNativeQuery(""" - set local hsadminng.tx_history_txid to ':txid'; + set local hsadminng.basis.tx_history_txid to ':txid'; """.replace(":txid", txId.toString())).executeUpdate(); em.createNativeQuery(""" set local hsadminng.tx_history_timestamp to ''; @@ -66,7 +66,7 @@ public abstract class ContextBasedTest { set local hsadminng.tx_history_timestamp to ':timestamp'; """.replace(":timestamp", txTimestamp.toString())).executeUpdate(); em.createNativeQuery(""" - set local hsadminng.tx_history_txid to ''; + set local hsadminng.basis.tx_history_txid to ''; """).executeUpdate(); }