我希望能够通过Maven将最新的更改应用到liquibase控制的数据库。我的POM包含:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.3.5</version>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.23</version>
</dependency>
</dependencies>
<configuration>
<changeLogFile>src/main/resources/config/database/db-changelog-master.xml</changeLogFile>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/myDb</url>
<username>${db.user}</username>
<password>${db.password}</password>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
,当我运行mvn liquibase:update
时,我得到以下内容:
[INFO] driver: com.mysql.jdbc.Driver
[INFO] url: jdbc:mysql://localhost:3306/myDb
[INFO] username: dbUser
[INFO] password: *****
[INFO] use empty password: false
[INFO] properties file: null
[INFO] properties file will override? false
[INFO] prompt on non-local database? true
[INFO] clear checksums? false
[INFO] changeLogFile: src/main/resources/config/database/db-changelog-master.xml
[INFO] context(s): null
[INFO] label(s): null
[INFO] number of changes to apply: 0
[INFO] drop first? false
[INFO] ------------------------------------------------------------------------
[INFO] Executing on Database: jdbc:mysql://localhost:3306/myDb
INFO 23/07/15 13:09: liquibase: Successfully acquired change log lock
INFO 23/07/15 13:09: liquibase: Reading from DATABASECHANGELOG
SEVERE 23/07/15 13:09: liquibase: src/main/resources/config/database/db-changelog-master.xml: src/main/resources/config/database/changesets-001.xml::1000::gavin: Change S
et src/main/resources/config/database/changesets-001.xml::1000::gavin failed. Error: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'tc_configuration'
already exists
liquibase.exception.DatabaseException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'tc_configuration' already exists
似乎Liquibase正在尝试重新运行已经执行的更改集。
是否有一种方法可以只运行新的变更集?
Liquibase在自己的表中跟踪已经执行的操作。在决定是否运行创建表tc_configuration的sql语句之前,它不会查看表tc_configuration是否存在。相反,如果具有给定id的更改集已经执行,它将检查自己的表。所以在你的例子中,tc_configuration表显然是在liquibase之外创建的,或者liquibase表被操纵了。
如果你从一个空数据库开始,并且只使用liquibase:update更新它,liquibase将始终只运行最新的更改,正好一次。