Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

afterEachMigrate fails, migration succeeds, but migration not written to schema_version #1025

Closed
cajnoj opened this issue May 27, 2015 · 5 comments
Labels
Milestone

Comments

@cajnoj
Copy link

@cajnoj cajnoj commented May 27, 2015

My afterEachMigrate SQL callback script failed due to some external reason.
According to the attached output, flyway thought that it rolled-back the patch that preceded the callback but it didn't. I suspect that the migration and the post-migration callback run in separate transactions.

[osuser@srv flyway]$ ./flyway -configFile=conf/file.conf migrate
Flyway 3.2.1 by Boxfuse

Database: jdbc:postgresql://redshifthost:5439/systemdb (PostgreSQL 8.0)
Validated 42 migrations (execution time 00:00.682s)
Executing SQL callback: beforeMigrate
Current version of schema "myschema": 1.4.1.0.1
Migrating schema "myschema" to version 1.5.0.0.2 - Description
Executing SQL callback: afterEachMigrate
Migrating schema "myschema" to version 1.5.0.0.3 - Description
Executing SQL callback: afterEachMigrate
Migrating schema "myschema" to version 1.5.0.0.4 - Description
Executing SQL callback: afterEachMigrate
ERROR: Migration of schema "myschema" to version 1.5.0.0.4 failed! Changes successfully rolled back.
ERROR:
Migration afterEachMigrate.sql failed
-------------------------------------
SQL State  : XX000
Error Code : 0
Message    : ERROR: could not complete because of conflict with concurrent transaction
Location   : ../Schema/afterEachMigrate.sql (/.../flyway/../Schema/afterEachMigrate.sql)
Line       : 2
Statement  : GRANT SELECT ON ALL TABLES IN SCHEMA myschema TO GROUP myschema_group
@cajnoj cajnoj changed the title Callback afterEachMigrate run in separate transaction Callback afterEachMigrate runs in a transaction separate from migration May 27, 2015
@cajnoj cajnoj changed the title Callback afterEachMigrate runs in a transaction separate from migration afterEachMigrate fails, migration succeeds, but migration not written to schema_version Jun 15, 2015
@InsaneOstrich
Copy link

@InsaneOstrich InsaneOstrich commented Jun 15, 2015

Yeah, if you look at DbMigrate.java in the source code, you can see that the beforeEachMigrate and afterEachMigrate callbacks are being run in independent transactions. This was causing issues for me when flyway was trying to re-apply a migration that had already been applied before the afterEachMigrate callback failed.

@cajnoj
Copy link
Author

@cajnoj cajnoj commented Jun 15, 2015

I think that this should be considered a bug.

@InsaneOstrich
Copy link

@InsaneOstrich InsaneOstrich commented Jun 15, 2015

I completely agree. It's very easy to reproduce as well.

@axelfontaine axelfontaine added this to the Flyway 4.0 milestone Jun 15, 2015
@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Oct 28, 2015

Do you feel a single transaction for all beforeEachMigrate callbacks, as well as the migration itself and all afterEachMigrate callbacks would be the way to go?

@InsaneOstrich
Copy link

@InsaneOstrich InsaneOstrich commented Oct 30, 2015

Yeah, doing it all in one transaction would be perfect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.