Tuesday, July 26, 2011

How to ignore failed database migrations

When using Grails database migration plugin, failing migrations is sign of some problem - usually some syntax error. But in some cases it is not needed and it is ok to ignore them. For example, I faced this problem while testing application which created db in memory from Hibernate entities. Some particular migrations, like ones dealing with existing records or legacy columns, were failing with no meaning.
Fortunately, there is easy way to ignore some migrations. Just add failOnError:'false' to change set definition and it will report exception in logs, but will continue with loading. There is example:

  changeSet(author: "user", id: "96", failOnError:'false') {
    update(tableName: "table") {
      column(name: "column", valueBoolean: false)
      where ('column is null')
    }
  }


This is good that it is specified per change set, as only these dealing with particular columns will be able to fail, it will be still strict with others. Only way it would be better, if there would be global property, so it would be still strict in production, but more forgiving in test environment.

No comments:

Post a Comment