I'm using Spring Boot 2.0.1 and liquibase-core-3.5.5
.
When I run the application from IntelliJ (which will run the main()
method) I see the following type of value in the Liquibase database column database.filename
:
db/changelog/changes/v0001.sql
If I create a fat jar with embedded Tomcat and run the application, the same changeset will appear in the database as:
BOOT-INF/classes/db/changelog/changes/v0001.sql
I would like these values to match so that I can run my applications as JAR files, but connect to a remote database from IntelliJ if debugging is necessary. (Note: this would be for a test database, I would not debug production in this way).
I have found references to logicalFilePath
(such as this SO question), but I don't believe this will provide what I need.
I have also tried debugging into the Liquibase code to determine if there is a way I can alter this value. The closest I've come is these two observations:
If there is a way to make these consistent, or possibly just change the filename
column to the actual filename (e.g. v0001.sql
), that would be best.
UPDATE
I have Liquibase setup as the following in Spring Boot:
My resources/db/changelog/db.changelog-master.yaml
file has the following contents:
databaseChangeLog:
- includeAll:
path: db/changelog/changes/
And then in resources/db/changelog/changes
I have individual *.sql
files that contain the SQL I want to run. I do not recall where I found this setup, but I don't have anything specific to "changesets", is this an error on my part?
To run the execute-sql command, specify the following parameters in the Liquibase properties file, environment variables, or the command prompt while running the command: URL, driver [optional], and user authentication information such as username and password.
I was able to use this by no longer using the includeAll
option in my db.changelog-master.yaml
file. The includeAll
option is a helpful way to get started quickly (and process all files in a specific directory), but it seems to be unadvisable for regular use. As mentioned here.
This is what I previously had in db.changelog-master.yaml
, don't use it this way.
databaseChangeLog:
- includeAll:
path: db/changelog/changes/
This is what I updated it to:
databaseChangeLog:
- include:
file: db/changelog/changes/v0001_users.sql
- include:
file: db/changelog/changes/v0002_accounts.sql
The important thing to note is that I'm specifically listing every single file that I want included, in the order I want it run. This is a little bit of a hassle, but well worth the change.
In the original version, the databasechangelog.filename
column would be different based on how the application was executed:
db/changelog/changes/v0001_users.sql
is how the column would appear when running from IntelliJBOOT-INF/classes/db/changelog/changes/v0001_users.sql
is how the column would appear when running from an executable jar.After making the change, both options above are the same, and no longer include BOOT-INF/classes/
as a prefix.
Thanks to the other answers that helped point me in the correct direction!
The logicalFilePath
attribute is exactly what you want. I was facing same issue with my projects where I was executing some parts with maven and some parts with spring-boot.
this question can also help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With