2
votes

I would like to be able to apply the latest changes to a liquibase controlled database via Maven. My POM contains:

<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>  

and when I run mvn liquibase:update I get the following:

[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

It appears that Liquibase is trying to re-run changesets that have already been executed.

Is there a way to run only the new changesets?

1
Just a guess: Did you run liquibase before your maven setup on the commandline? Liquibase uses the path of the file to identify a changeset and the path might be different now that you try to let it run from within maven... - Jens
in case this is the file names clash, you might have to fix your migrations with logicalFilePath . - Mykola Gurov

1 Answers

3
votes

Liquibase keeps track of what has already been executed in its own tables. It will not look if the table tc_configuration exists, before deciding whether to run the sql statement that creates it. Instead, it will check in its own tables if a changeset wit a given id has been executed. So in your case, apparently, the tc_configuration table has been created outside of liquibase, or liquibase tables have been manipulated.

If you start with an empty database and only update it with liquibase:update, liquibase will always run only the newest changes, exactly once.