diff --git a/src/main/resources/config/liquibase/historicization/historicization.xml b/src/main/resources/config/liquibase/historicization/historicization.xml new file mode 100644 index 00000000..9f5f515d --- /dev/null +++ b/src/main/resources/config/liquibase/historicization/historicization.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + CREATE OR REPLACE FUNCTION historicize() + RETURNS trigger + AS $$ + BEGIN + IF (TG_OP = 'INSERT') OR (TG_OP = 'UPDATE') THEN + EXECUTE 'INSERT INTO history VALUES (txid_current(), now()) ON CONFLICT DO NOTHING'; + EXECUTE format('INSERT INTO %I_history VALUES (DEFAULT, txid_current(), False, $1.*)', TG_TABLE_NAME) USING NEW; + RETURN NEW; + ELSE -- assuming TG_OP = 'DELETE' + EXECUTE 'INSERT INTO history VALUES (txid_current(), now()) ON CONFLICT DO NOTHING'; + EXECUTE format('INSERT INTO %I_history VALUES (DEFAULT, txid_current(), True, $1.*)', TG_TABLE_NAME) USING OLD; + RETURN OLD; + END IF; + END; + $$ + LANGUAGE plpgsql; + + + + + diff --git a/src/main/resources/config/liquibase/master.xml b/src/main/resources/config/liquibase/master.xml index c4daff8a..9842d7a3 100644 --- a/src/main/resources/config/liquibase/master.xml +++ b/src/main/resources/config/liquibase/master.xml @@ -3,6 +3,8 @@ xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd"> + + @@ -11,6 +13,8 @@ + + @@ -18,7 +22,10 @@ - + + + +