How to createTrigger?


I’m writing a changeset where I want to add triggers, but the example on the document doesn’t really explain all of it.

Also I’m a little bit confused what is really mandatory. Do I need to provide a trigger name and trigger body if I add a path to an SQL script which is creating the trigger?

Hi @mwolski

If you have the logic written in separate SQL file then you can do something like :

<changeSet  author="liquibase-docs" id="createTrigger-example">
    <pro:createTrigger catalogName="cat"  
           comments="A String" 
           dbms="h2, !oracle, mysql"
           scope="A String" 
           triggerName="A String">A String</pro:createTrigger> 

You will have to provide the triggerName and path to your SQL file where the logic is written. And other attribute values should be provided accordingly.

If you are trying to have trigger code written in changeset itslef, you could do something like this :

<changeSet id="3" author="me">
        DROP TRIGGER IF EXISTS add_current_date_to_my_table ON my_table;
        CREATE TRIGGER add_current_date_to_my_table BEFORE UPDATE ON my_table FOR EACH ROW EXECUTE PROCEDURE change_update_time();
        DROP TRIGGER add_current_date_to_my_table ON my_table;

Hope this helps!

Rakhi Agrawal

1 Like

Thank you for the fast response. Ok I just figured our that createTrigger requires a pro license of liquibase.
Is there a difference in using createTrigger or just referencing an SQL script?

I solved my problem referencing the sql script :slight_smile: Thanks for the solution

1 Like

Good to know that! :slight_smile: