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

MetaDataTable not updated with autoCommit false #1534

Closed
fabian opened this issue Feb 17, 2017 · 2 comments
Closed

MetaDataTable not updated with autoCommit false #1534

fabian opened this issue Feb 17, 2017 · 2 comments
Labels
Milestone

Comments

@fabian
Copy link

@fabian fabian commented Feb 17, 2017

This seems to affect Flyway 4.1 and later. So far we've been using Flyway 3 where this wasn't an issue.

If the DataSource used for Flyway has autoCommit=false, the meta data table schema_version is not updated after a migration has been executed.

I've searched around in the source code and I suspect the bug has probably been introduced with #851 when the TransactionTemplate was replaced with a metaDataTable lock:

b258cb4#diff-f8b70833a92c52372a5327e6765f414dL148

Before this commit, applying the migration and updating the meta data table (applyMigration) were wrapped in one transaction which made sure the meta data table changes got committed.

Maybe a TransactionTemplate should be added in MetaDataTableImpl.addAppliedMigration?

@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Feb 17, 2017

Note for future issues: please use the template we provided as it avoids the need to ask the following questions.

Which database + version are you using?

Can you share a small test case that reproduces the issue?

@fabian
Copy link
Author

@fabian fabian commented Feb 17, 2017

I skipped the template because it seemed mostly irrelevant. I've filled it now out below. I have now also created some test code showing the issue: https://github.com/fabian/flyway-autocommit-issue

What version of Flyway are you using?

4.1.1

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin, SBT plugin, ANT tasks)

Java API

What database are you using (type & version)?

MySQL 5.7.17

What operating system are you using?

macOS 10.12.3

What did you do?

(Please include the content causing the issue, any relevant configuration settings, and the command you ran)

HikariDataSource dataSource = new HikariDataSource();
dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/flyway");
dataSource.setUsername("root");
dataSource.setAutoCommit(false);

Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
flyway.migrate();
What did you expect to see?

Migration in schema_version table.

What did you see instead?

Empty schema_version table.

@axelfontaine axelfontaine added this to the Flyway 4.1.2 milestone Feb 17, 2017
pradheeps pushed a commit to pradheeps/flyway that referenced this issue Mar 7, 2017
dohrayme pushed a commit to dohrayme/flyway that referenced this issue Feb 3, 2020
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
2 participants
You can’t perform that action at this time.