Maven Liquibase插件执行以前的更改集

时间:2015-07-23 12:14:32

标签: maven liquibase

我希望能够通过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正在尝试重新运行已经执行的变更集。

有没有办法只运行新的变更集?

1 个答案:

答案 0 :(得分:2)

Liquibase会跟踪已在自己的表中执行的内容。在决定是否运行创建它的sql语句之前,不会查看表tc_configuration是否存在。相反,如果已经执行了具有给定id的变更集,它将检查自己的表。所以在你的情况下,显然,tc_configuration表是在liquibase之外创建的,或者liquibase表已被操作。

如果你从一个空的数据库开始,只用liquibase:update更新它,liquibase将只运行最新的更改,只需一次。