Add trigger and function for updated_date and created_date column in gepafin_schema

This commit is contained in:
harish
2024-09-23 18:19:14 +05:30
parent 2e2ad1c9e1
commit b28f5b71fc
3 changed files with 83 additions and 2 deletions

View File

@@ -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,4 +710,33 @@
<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">
<!-- 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>
<!-- Procedure for setting created_date only on insert -->
<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;
RETURN NEW;
END;
$$;
</createProcedure>
</changeSet>
</databaseChangeLog>