[FIXED] add a sql file in different module to changeset in liquibase

Issue

my project structure is like below described.

enter image description here

In myApp (gradle), i have used liquibase for manage schema changes. So what i want is to run sqlFiles (mySqlFile1.sql, mySqlFile2.sql and mySqlFile3.sql) from my "database" module in my changelog as a changeset.

I know how to run a sql file in the same directory using sqlFile tag. But since these files are in a separate module, i need some help.

Solution

i was able to do this with the help of gradle task. I tried to find a way to achieve this using liquibase but for me i couldn’t find any.

So what i did was i added a gradle task in my build.gradle file to copy the sql file from the database forler and paste in inside my resources folder like below.

task myCustomTask() {

    copy {
        from "${rootProject.projectDir}/database/migration/mySqlFile1.sql"
        into '/src/main/resources/db/'
    }
        copy {
        from "${rootProject.projectDir}/database/migration/mySqlFile2.sql"
        into '/src/main/resources/db/'
    }
    copy {
        from "${rootProject.projectDir}/database/migration/mySqlFile3.sql"
        into '/src/main/resources/db/'
    }

}

build.dependsOn myCustomTask

So my above copy task happens before the application builds. That means by the time liquibase run the changelog, these sql file are available in the resources folder.

So what i did was after adding this gradle copy task, i added a seperate changeset to run the the sql files in the resources folder.

Thats how i was able to resolve my issue.

Answered By – Dushan

Answer Checked By – Candace Johnson (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published