Merge pull request #34 from Kitzanos/feature/GEPAFINBE-17
GEPAFINBE-17 (Added Trigger and Function)
This commit is contained in:
@@ -539,7 +539,7 @@
|
||||
<dropColumn tableName="FORM"
|
||||
columnName="order_no" />
|
||||
</changeSet>
|
||||
|
||||
|
||||
<changeSet id="03-09-2024_1" author="Rajesh Khore">
|
||||
<sql>
|
||||
TRUNCATE TABLE FORM_FIELD RESTART IDENTITY;
|
||||
@@ -696,7 +696,7 @@
|
||||
path="classpath:db/dump/inserted_form_field_data_13_09_2024.sql" />
|
||||
</changeSet>
|
||||
|
||||
|
||||
|
||||
<changeSet id="12-09-2024_1" author="Rajesh Khore">
|
||||
<addColumn tableName="flow_edges">
|
||||
<column name="tracking_id" type="VARCHAR(255)"></column>
|
||||
@@ -710,6 +710,35 @@
|
||||
<sqlFile dbms="postgresql"
|
||||
path="classpath:db/dump/updated_form_field_data_16-09-2024.sql" />
|
||||
</changeSet>
|
||||
<changeSet id="23-09-2024_1" author="Harish Bagora" dbms="postgresql">
|
||||
<!-- Procedure for automatically setting the updated_date -->
|
||||
<createProcedure>
|
||||
CREATE OR REPLACE FUNCTION gepafin_schema.clock_timestamp_updated_date_column()
|
||||
RETURNS TRIGGER
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
BEGIN
|
||||
NEW.updated_date = clock_timestamp();
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$;
|
||||
</createProcedure>
|
||||
|
||||
<createProcedure>
|
||||
CREATE OR REPLACE FUNCTION gepafin_schema.clock_timestamp_created_date_column()
|
||||
RETURNS TRIGGER
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
BEGIN
|
||||
IF NEW.created_date IS NULL THEN
|
||||
NEW.created_date = clock_timestamp();
|
||||
END IF;
|
||||
NEW.updated_date = NEW.created_date;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$;
|
||||
</createProcedure>
|
||||
</changeSet>
|
||||
|
||||
<changeSet id="23-09-2024_1" author="Rajesh Khore">
|
||||
<createTable tableName="saml_response">
|
||||
|
||||
@@ -5,4 +5,5 @@
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.23.xsd">
|
||||
|
||||
<include file="db/changelog/db.changelog-1.0.0.xml"/>
|
||||
<include file="db/changelog/dynamic-triggers.xml" />
|
||||
</databaseChangeLog>
|
||||
|
||||
51
src/main/resources/db/changelog/dynamic-triggers.xml
Normal file
51
src/main/resources/db/changelog/dynamic-triggers.xml
Normal file
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog
|
||||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.0.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.23.xsd">
|
||||
<changeSet id="23-09-2024_3" author="Harish Bagora" runAlways="true">
|
||||
<sql splitStatements="false">
|
||||
DO $$
|
||||
DECLARE
|
||||
r RECORD;
|
||||
BEGIN
|
||||
-- Loop through all tables in the schema that have the 'updated_date' column
|
||||
FOR r IN (
|
||||
SELECT table_name
|
||||
FROM information_schema.columns
|
||||
WHERE column_name = 'updated_date'
|
||||
AND table_schema = 'gepafin_schema'
|
||||
)
|
||||
LOOP
|
||||
EXECUTE format(
|
||||
'CREATE OR REPLACE TRIGGER tg_gepafin_schema_updated_at_%I
|
||||
BEFORE UPDATE ON gepafin_schema.%I
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION gepafin_schema.clock_timestamp_updated_date_column()',
|
||||
r.table_name, r.table_name
|
||||
);
|
||||
END LOOP;
|
||||
|
||||
-- Loop through all tables in the schema that have the 'created_date' column
|
||||
FOR r IN (
|
||||
SELECT table_name
|
||||
FROM information_schema.columns
|
||||
WHERE column_name = 'created_date'
|
||||
AND table_schema = 'gepafin_schema'
|
||||
)
|
||||
LOOP
|
||||
EXECUTE format(
|
||||
'CREATE OR REPLACE TRIGGER tg_gepafin_schema_created_at_%I
|
||||
BEFORE INSERT ON gepafin_schema.%I
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION gepafin_schema.clock_timestamp_created_date_column()',
|
||||
r.table_name, r.table_name
|
||||
);
|
||||
END LOOP;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
</sql>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
Reference in New Issue
Block a user