1

I was wondering how Flyway handles exceptions thrown from classes that implement the JdbcMigration interface.

Does Flyway roll back the transaction? Does it stop doing further migrations?

Shilpam
  • 363
  • 3
  • 14
  • 2
    Yes, it will rollback the transaction until the latest well executed script or latest commit done. Then it will log the Exception and notify you (depending how you configure it). – Luiggi Mendoza Jul 16 '13 at 16:26
  • This might be helpful :http://stackoverflow.com/questions/4959299/how-to-roll-back-migrations-using-flyway/4959332#4959332 – Suresh Atta Jul 16 '13 at 16:26
  • @LuiggiMendoza Your comment is correct. Turn it into an answer. – Axel Fontaine Jul 17 '13 at 13:03
  • All I know is that I had to clean several "exceptions" from flyway migration off my car windshield this morning. – Hot Licks Jul 17 '13 at 15:27

1 Answers1

4

Does Flyway roll back the transaction?

Yes, it will rollback the transaction until the latest well executed script or latest commit done. Then it will log the Exception and notify you (depending how you configure it).

Does it stop doing further migrations?

AFAIK that's the common behavior, it will stop if it encounters an error.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • 1
    Aren't most DBs unable to do rollback on more than one DDL statement? How will Flyway deal with a script that's had only half its statements executed? – Aleksandr Dubinsky Aug 05 '14 at 17:43
  • @AleksandrDubinsky it is like an atomic operation: all or nothing, per script, unless you modify that configuration. – Luiggi Mendoza Aug 05 '14 at 17:44
  • 1
    From MySQL docs: "Some statements cannot be rolled back. In general, these include data definition language (DDL) statements, such as those that create or drop databases, those that create, drop, or alter tables or stored routines." Ie, any transaction with such a statement can't be rolled back. Some DBs do support DDL transactions (eg PostgreSQL). Others support a single DDL statement per transaction. Liquibase opens a transaction per statement and records it in the metadata, which may help (it knows where it left off). For Flyway, it sounds like you'd better recover the DB from a snapshot. – Aleksandr Dubinsky Aug 05 '14 at 18:03