Redgate Flyway

Migration error and logging handling

dWhen Flyway executes SQL statements it reports all warnings returned by the database. These originate from the database driver rather than Flyway.

In case an error is returned Flyway displays it with all necessary details, marks the migration as failed and automatically rolls it back if possible.

The default behavior is usually reasonable but there may be some situations where you may want to tweak it. For example:

  • treat an error as a warning as you know your migration will handle it correctly later
  • treat a warning as an error as you prefer to fail fast to be able to fix the problem sooner
  • treat a warning as an information message
  • perform an additional action when a specific error or warning is being emitted by the database

Configuration

EDITION: TEAMS

The default behaviour can be overridden using the errorOverrides setting.

Click here to see a tutorial on using error overrides.

Advanced programmatic configuration

As an alternative to the simple declarative syntax presented above, you can also fully customize the behavior of Flyway following the execution of a statement by implementing a Java-based callback which listens to the afterEachMigrateStatement, afterEachMigrateStatementError, afterEachUndoStatement and afterEachUndoStatementError events.

Common scenarios for tweaking output

Display SQL Server PRINT messages as simple info messages

By default when a SQL Server PRINT statement executes, the message is returned as a warning to the client. This means that the following statements:

PRINT 'Starting ...';
PRINT 'Done.';

produce the following output by default:

WARNING: DB: Starting ... (SQL State: S0001 - Error Code: 0)
WARNING: DB: Done. (SQL State: S0001 - Error Code: 0)

To force these PRINT statements to produce simple info messages (with no SQL State and Error Code details) instead of warnings, all one needs to do is add the following to Flyway's configuration:

flyway.errorOverrides=S0001:0:I-

With that setting in place the output then simply becomes info messages with no SQL State and Error Code details:

Starting ...
Done.

Throw an error when Oracle stored procedure compilation fails

By default when an Oracle stored procedure compilation fails, the driver simply returns a warning which is being output by Flyway as

DB: Warning: execution completed with warning (SQL State: 99999 - Error Code: 17110)

To force Oracle stored procedure compilation issues to produce errors instead of warnings, all one needs to do is add the following to Flyway's configuration:

flyway.errorOverrides=99999:17110:E

All Oracle stored procedure compilation failures will then result in an immediate error.

 

Didn't find what you were looking for?