Liquibase Stored Proc's management

What we do is something like this:

\---liquibase
    |   changelog.xml
    |   procedures.xml
    |   
    +---procedures
            procedure_one.sql
            procedure_two.sql

changelog.xml simply includes procedures.xml. Inside procedures.xml we then have something like this:

<changeSet author="arthur" id="1" runOnChange="true" runInTransaction="true">
    <sqlFile path="procedures/procedure_one.sql"
             encoding="UTF-8"
             relativeToChangelogFile="true"
             endDelimiter=";"
             splitStatements="true"/>

</changeSet>

<changeSet author="arthur" id="2" runOnChange="true" runInTransaction="true">
    <sqlFile path="procedures/procedure_two.sql"
             encoding="UTF-8"
             relativeToChangelogFile="true"
             endDelimiter=";"
             splitStatements="true"/>

</changeSet>

Of course runInTransaction="true" only makes sense if your DBMS supports transactional DDL.

Each SQL script for the procedures is self contained and re-creates the procedure using create or replace. For DBMS that do not support create or replace we usually do a (conditional) drop procedure; create procedure ... in there.

By explicitly including the files (instead of using includeAll) we have control over the order in which the procedures and functions are created (important if one uses another).

If you add a new procedure, you add a new SQL script and a new changeSet to the procedures.xml

Tags:

Liquibase