Perform a liquibase:rollback from the command line when properties are in Spring-boot files (application.properties) and not liquibase.properties

Viewed 1046

I am using Spring-boot with Liquibase, and my database configuration is set in an application.properties file.

spring.datasource.url=jdbc:postgresql://localhost:5432/comptesfrance
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.datasource.driver=org.postgresql.Driver
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.postgis.PostgisDialect
spring.jpa.database-platform=org.hibernate.spatial.dialect.postgis.PostgisDialect
spring.liquibase.change-log=classpath:/db/changelog/compte-france-postgis-changelog.xml

With the help of the maven plugins liquibase-core and liquibase-maven-plugin everything is working well and my database structure is updated smoothly during the project lifetime.

However, I made a mistake lately in my development environment and I have to use the command line to perform a rollback. Remove a changeset I've just created.

I enter a bash shell and execute :

mvn liquibase:rollback -Dliquibase.rollbackCount=1

but it fails with the message : "The database URL has not been specified either as a parameter or in a properties file".

I could set a :

<propertyFile>${project.build.directory}/classes/liquibase.properties</propertyFile>

in the configuration of the liquibase-maven-plugin plugin if I had such file... But my properties are in my application.properties file instead.

If I attempt to mention this application.properties file to Liquibase, with a <propertyFile>${project.basedir}/src/main/resources/application.properties</propertyFile> configuration, Liquibase doesn't recognize its entries :

[INFO] Parsing Liquibase Properties File
[INFO]   File: /home/marc/dev/Java/comptes-france/metier-et-gestion/dev/DAOPostgis/../ApplicationMetierEtGestion/src/main/resources/application.properties
[INFO]   'spring.jpa.properties.hibernate.dialect' in properties file is not being used by this task.
[INFO]   'spring.datasource.url' in properties file is not being used by this task.
[INFO]   'spring.datasource.password' in properties file is not being used by this task.
[INFO]   'spring.datasource.username' in properties file is not being used by this task.
[INFO]   'spring.jpa.database-platform' in properties file is not being used by this task.
[INFO]   'spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation' in properties file is not being used by this task.
[INFO]   'spring.liquibase.change-log' in properties file is not being used by this task.
[INFO]   'spring.datasource.driver' in properties file is not being used by this task.

Is there a way through the spring-boot:run commands to issue a rollback ?

It would allow spring-boot to send to Liquibase the configuration it knows and use well already.

1 Answers

The property names within springs application.properties and liquidate.properties are not compatible. You have three options

  1. just create a separate liquibase.properties file with the content you need - see liquibase doc as you only need to to fix your current setup
  2. give the database parameters via command line arguments

    mvn liquibase:rollback -Dliquibase.rollbackCount=1    -Dliquibase.url=jdbc:postgresql://localhost:5432/comptesfrance -Dliquibase.username
    

    see rollback goal for all arguments

  3. if you need a permanent solution, then you may add the liquibase properties into your application.properties and reuse them in the same file. i.e.

    liquibase.url=jdbc:postgresql://localhost:5432/comptesfrance
    spring.datasource.url=${liquibase.url}
    

    ( I havn't tested this)

Related