Reputation: 675
I'm using spring-boot with the liquibase-maven-plugin to generate database changes according to my classes, but the "mvn compile liquibase: diff" command always generates removals and inclusions of indexes and foreign keys even though the database is updated and has no change in the classes (and therefore should have no change in the database).
Anyone have any idea if this is right or how to avoid it? I want only the new changes to database to be generated in change sets of the Project.
Upvotes: 11
Views: 1243
Reputation: 694
First of all, I think you are missing the liquibase-hibernate4 maven plugin.
From the project Readme.md
:
This extension lets you use your Hibernate configuration as a comparison database for diff, diffChangeLog and generateChangeLog in Liquibase.
Which actually means that you can use it to compare the real database with your java entities in order to generate the new changelogs.
As the project wiki suggest, it's important to keep in mind that you need to take a look to the new changelogs and modify it manually if there is something wrong.
I also recommend you to read this article from Baeldung that explains that:
Your pom.xml
should look like:
...
<dependencies>
...
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.1</version>
</dependency>
...
</dependencies>
...
<plugins>
...
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<propertyFile>src/main/resources/liquibase.properties</propertyFile>
</configuration>
<dependencies>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate4</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.7.3.RELEASE</version>
</dependency>
</dependencies>
</plugin>
...
</plugins>
...
And your src/main/resources/liquibase.properties
:
url=jdbc:mysql://localhost:3306/your_db
username=your_user
password=your_pw
driver=com.mysql.jdbc.Driver #orYourDriver
outputChangeLogFile=src/main/resources/liquibase-outputChangeLog.xml
hibernate:spring:your.model.package?dialect=org.hibernate.dialect.MySQLDialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
Im not sure which persistence storage are you using but please be sure to use the correct drivers and datasource urls.
After configure it completely, you should be able to run mvn liquibase:diffChangeLog
to generate the new changelogs.
Upvotes: 2