Search code examples
springpostgresqlspring-bootliquibaseh2db

Liquibase DB specific scripts for single project


I have spring boot project with postgresql as main DB and H2 as in-memory DB for testing. I've added a PL/pgSQL procedure to execute some custom logic and now my tests stop working. how liquibase users usually resolve such cases?

my procedure is :

CREATE OR REPLACE FUNCTION <name>() RETURNS trigger AS'
            BEGIN
                DELETE FROM gator_device
                WHERE id = OLD....
                RETURN NULL ;
            END;'
            LANGUAGE plpgsql;

            CREATE TRIGGER <name>
            AFTER DELETE ON <name>
            FOR EACH ROW EXECUTE PROCEDURE <name>();

Solution

  • As mentioned in the comments to your question, you would need to mark the changeset that creates the function with the attribute dbms="postgresql". When Liquibase is deciding which changesets to apply to a database, it can skip a changeset if that changeset will only work on certain database types. To be completely cross-platform, you would need to write 'equivalent' changesets that work on each of the databases that you want to support, and mark each of them with the dbms that each changeset supports.