Reputation: 1058
I recently started to work on a branch that had been under development by a dev who left the organization and it looks like he left the associated test environment schema in a bad state.
There is a Liquibase change file that makes a number of changes that are all necessary for the code to run, but it looks like the associated schema has some of the changes applied.
I try never to update any schemata by hand, especially when not my personal dev environment, so I was hoping to make the existing (fairly complicated) changes work.
The error that I get is this:
SEVERE 12/12/12 12:15 PM:liquibase: Change Set db/changelogs/linechanges.xml::14::limit failed. Error: Error executing SQL ALTER TABLE limit ADD id serial: ERROR: column "id" of relation "lineitem_limitgroup" already exists liquibase.exception.DatabaseException: Error executing SQL ALTER TABLE limit ADD id serial: ERROR: column "id" of relation "limit" already exists at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:62) at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:104) at liquibase.database.AbstractDatabase.execute(AbstractDatabase.java:1075) at liquibase.database.AbstractDatabase.executeStatements(AbstractDatabase.java:1059) at liquibase.changelog.ChangeSet.execute(ChangeSet.java:317) at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:27) at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:58) at liquibase.Liquibase.update(Liquibase.java:113) at org.liquibase.maven.plugins.LiquibaseUpdate.doUpdate(LiquibaseUpdate.java:31) at org.liquibase.maven.plugins.AbstractLiquibaseUpdateMojo.performLiquibaseTask(AbstractLiquibaseUpdateMojo.java:24) at org.liquibase.maven.plugins.AbstractLiquibaseMojo.execute(AbstractLiquibaseMojo.java:302) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
Note that this change file includes multiple changeSets. When I inspect the schema, it looks like the changes from some of the changeSets have been applied, but some of the others have no changes applied.
So, is there a way to tell liquibase (preferably via the Maven plugin) to ignore failed changeSets and continue?
Or (less usefully) is there a way to tell liquibase to apply some changeSets and not others?
Thanks!!!
Upvotes: 1
Views: 2094
Reputation: 437
Looks like your changeset was updated unintentionally, so you are seeing the issue. Its a good practice to create new changesets for the changes in schema, etc of the already created entities rather than updating the existing changesets.
Having said that :
In your log, check that if someother change set is already adding that column.Yes there are ways to tell liquibase to apply some changes and not other.
One workaround is : since your file is already having issues, you can make all the previous changes to go under any correctly run change set. Since the unique identification of the changeset is based on - author, change, changeSetID .Since this has been run once, it will not go and run it again no matter what sql is inside it.
Upvotes: 1
Reputation: 2490
I thing your best option is to use a Liquibase precondition to tell it to run the chanset in error only if the column doen't exist. You will have to use the tag columnExists like this :
<preConditions>
<not>
<columnExists columnName="id" tableName="limit" schemaName="yourSchemaNameHere" />
</not>
</preConditions>
It will mark the script as run without actually running any update if you already have the id column in the limit table.
You also have two other options :
First option. You can set the attribute failOnError to false on the changesets that trigger an error. The error prone changesets will be run up to the point they trigger an error. The next changesets will run normally.
Use this with care since it doesn't rollback the changeset on error and it doesn't mark the changeset as run either. Also note that if you already hava a changeset with this attribute set to false, that may explain why you have a partial update.
Second option, insert a row in the table DATABASECHANGELOG to indicate to Liquibase that it doesn't have to run a particular changeset. Actually, it means that the changeset ran successfuly, but the result is that Liquibase will never try to run it again anyway.
Upvotes: 0
Reputation: 9345
Liquibase won't apply a changeset twice. But probably some of the same (or incompatible) changes were made in different changesets in other branches. I think you have no other choice but to manually edit the changesets of this branch so that they apply cleanly.
Upvotes: 0