Search code examples
azure-devopsliquibasecicd

Is there a way to include whole folder with changelogs in Liquibase db versioning?


I have a problem with Liquibase database versioning, because I want to include all changelog files in folder, without specifing its names and do update using them. Is that possible? My structure:

db--

|

--release-v1

     |

     --fistchangelog.sql

     --secondchangelog.sql

|

--release-v2

     |

     --newchangelog.sql

...

And with every release I want to use all *.sql files from its folder. I don't want to hardcode names of sql files. I use only liquibase command lines for CI/CD in Azure.

I found something like (liquibase.org/get-started/best-practices), but it only works with xml files and I use sql extension.

I have one idea but it seems bad for me and I ll use it as a last resort. Just making a loop, for every file in folder, in cmd...

Does someone know is there a simpler and better way?


Solution

  • You can do like this: have a parent change log file:

    databaseChangeLog = {
    include file: "releases/ref1.groovy", relativeToChangelogFile: true
    include file: "releases/release1.groovy", relativeToChangelogFile: true
    include file: "releases/release2.groovy", relativeToChangelogFile: true
    include file: "releases/release3.groovy", relativeToChangelogFile: true
    }
    

    in releases folder ref1 file can have:

    databaseChangeLog = {
    include file: "../tables/changelog.groovy", relativeToChangelogFile: true    
    }
    

    So inside the same releases folder you can have tables folder which then have create, delete update folders. So you can have another file in tables like, in create folder, you have all the necessary files that have been added in different releases:

    databaseChangeLog = {
    include file: "create/changelog.groovy", relativeToChangelogFile: true
    include file: "update/changelog.groovy", relativeToChangelogFile: true
    include file: "data/changelog.groovy", relativeToChangelogFile: true
    

    }

    finally in releases main folder you can add a file like release1.groovy:

    databaseChangeLog = {
        include file: "../tables/create/your_structured_sql_file.groovy", 
         relativeToChangelogFile: true
    }
    

    These are in groovy but the structuring is the same.