Looking at the history of database stored procedures and functions and the like is notoriously difficult. It occurs to me that I could put all our stored procedures and functions in git and just reference them using the sqlFile attribute in a new changeSet whenever a new change would need to be applied. However, from what I’ve read, it seems as if any changeSet that reference a sqlFile that has been changed, would then have a different md5 and liquibase would then try to apply it.
We are using the best practice approach where we have one master changelog file per schema and from there we reference a new changelog file per new release.
<databaseChangeLog xmlns="<a href='http://www.liquibase.org/xml/ns/dbchangelog"' target='_blank' rel='noreferrer'>http://www.liquibase.org/xml/ns/dbchangelog"</a> xmlns:xsi="<a href='http://www.w3.org/2001/XMLSchema-instance"' target='_blank' rel='noreferrer'>http://www.w3.org/2001/XMLSchema-instance"</a> xsi:schemaLocation="<a href='http://www.liquibase.org/xml/ns/dbchangelog' target='_blank' rel='noreferrer'>http://www.liquibase.org/xml/ns/dbchangelog</a> <a href='http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">' target='_blank' rel='noreferrer'>http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd"></a></div>
<include relativeToChangelogFile="true" file="catalog.db.changelog-2017.Q3.R1.xml"/></div>
<include relativeToChangelogFile="true" file="catalog.db.changelog-2017.Q3.R2.xml"/></div>
<include relativeToChangelogFile="true" file="catalog.db.changelog-2017.Q4.R1.xml"/></div>
<include relativeToChangelogFile="true" file="catalog.db.changelog-2018.Q1.R1.xml"/></div>
<include relativeToChangelogFile="true" file="catalog.db.changelog-2018.Q2.R1.xml"/></div>
<include relativeToChangelogFile="true" file="catalog.db.changelog-2018.Q3.R1.xml"/></div>
<include relativeToChangelogFile="true" file="catalog.db.changelog-2018.Q4.R1.xml"/></div>
<include relativeToChangelogFile="true" file="catalog.db.changelog-2019.Q1.R1.xml"/></div>
<include relativeToChangelogFile="true" file="catalog.db.changelog-2019.Q1.R2.xml"/></div>
<include relativeToChangelogFile="true" file="catalog.db.changelog-2019.Q1.R3.xml"/></div>
<include relativeToChangelogFile="true" file="catalog.db.changelog-2019.Q2.R1.xml"/></div>
</databaseChangeLog></div></div>
It occurs to me that maybe the right approach for having an individual sqlFile per function/stored proc would be to have a single include that would look something like this:
<include relativeToChangelogFile="true" file="catalog.db.changelog-functions.xml"/></div></div></div>
And in there, I’d have a bunch of changeSets that reference the individual sqlFiles and then any time one of the referenced sqlFiles changes, the changeSet would be reapplied. Is that how it would work?
<?xml version="1.0" encoding="UTF-8"?></div>
<databaseChangeLog</div>
xmlns="<a href='http://www.liquibase.org/xml/ns/dbchangelog"' target='_blank' rel='noreferrer'>http://www.liquibase.org/xml/ns/dbchangelog"</a></div>
xmlns:xsi="<a href='http://www.w3.org/2001/XMLSchema-instance"' target='_blank' rel='noreferrer'>http://www.w3.org/2001/XMLSchema-instance"</a></div>
xsi:schemaLocation="<a href='http://www.liquibase.org/xml/ns/dbchangelog' target='_blank' rel='noreferrer'>http://www.liquibase.org/xml/ns/dbchangelog</a></div>
<a href='http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">' target='_blank' rel='noreferrer'>http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd"></a></div>
</div>
<changeSet id="function1" author="vrodrigu"></div>
<sqlFile path="path/to/function1.sql"/></div>
</changeSet></div>
</div>
<changeSet id="function2" author="vrodrigu"></div>
<sqlFile path="path/to/function2.sql"/></div>
</changeSet></div>
</div>
<changeSet id="function3" author="vrodrigu"></div>
<sqlFile path="path/to/function3.sql"/></div>
</changeSet></div>
</div>
</databaseChangeLog></div>
```</div>