Liquibase ignores DB content and creates diff from scratch

1k Views Asked by At

I have a project based on Spring Boot and Hibernate. I use Liquibase for migrations. Every time I run mvn liquibase:diff it makes a full changeset based on my models like my Postgres DB is completely empty. I expect Liquibase to create only delta. What am I missing?

Maven build is successful, the only warning is:

[WARNING] Did not find schema 'mydb' to snapshot

Here is Maven configuration:

           <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>${liquibase.version}</version>
                <configuration>
                    <propertyFile>src/main/resources/liquibase/config/liquibase.properties
                    </propertyFile>
                    <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.liquibase.ext</groupId>
                        <artifactId>liquibase-hibernate5</artifactId>
                        <version>3.10.1</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-web</artifactId>
                        <version>${spring.boot.starter.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-data-jpa</artifactId>
                        <version>${spring.boot.starter.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-validator</artifactId>
                        <version>6.1.0.Final</version>
                    </dependency>
                </dependencies>
            </plugin>

liquibase.properties

changeLogFile=src/main/resources/liquibase/liquibase-changeLog.xml
diffChangeLogFile=src/main/resources/liquibase/liquibase-changeLogDiff.xml
outputChangeLogFile=src/main/resources/liquibase/liquibase-new-changeLog.xml
url=jdbc:postgresql://localhost:5432/mydb
defaultSchemaName=mydb
username=postgres
password=postgres
driver=org.postgresql.Driver

referenceDriver=liquibase.ext.hibernate.database.connection.HibernateDriver
referenceUrl=hibernate:spring:com.project.model?dialect=org.hibernate.dialect.PostgreSQLDialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy

application.properties

spring.datasource.url = jdbc:postgresql://localhost:5432/mydb
spring.datasource.username = postgres
spring.datasource.password = postgres

spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation = true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect

spring.jpa.hibernate.ddl-auto = none

# Liquibase
spring.liquibase.change-log = classpath:liquibase/liquibase-changeLog.xml
1

There are 1 best solutions below

0
On

In my case, the issue with diff changelog not being generated ([WARNING] Did not find schema ... to snapshot) was fixed by specifying the correct default DB schema (defaultSchemaName) - public (in the case for Postgres). Note: not all database vendors organize their data in schemes.

If you have problems finding out what DB schema is the default one - please try to get rid of the 2 parameters in liquibase config:

  1. defaultSchemaName
  2. referenceDefaultSchemaName

Here's a similar GitHub issue posted on Liquibase repo: https://github.com/liquibase/liquibase/issues/2950

And here's an explanation of what defaultSchemaName parameter is: https://stackoverflow.com/a/29774936/8581009