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

Fix #436: ManualStepMigration not working #469

Merged
merged 6 commits into from
Oct 29, 2018
Merged

Fix #436: ManualStepMigration not working #469

merged 6 commits into from
Oct 29, 2018

Conversation

gfx
Copy link
Member

@gfx gfx commented Oct 28, 2018

Fix #436

There is a bug that the DB version (user_version) is not updated when the manual step migrations do not call execSQL (or wrappers of it).

To fix it, always update DB version just like as when migration steps are empty.


As @k-kagurazaka suggested in #469 (comment), there as another problem in #436 ... the default migration engine is SchemaDiffMigration.

In this PR (esp. at c36a3c7), Orma always uses OrmaMigraion to correctly start ManualStepMigration.

@gfx gfx requested a review from k-kagurazaka October 29, 2018 00:57
@@ -186,6 +192,8 @@ public void run() {
}
}
});

saveStep(db, version, MIGRATION_COMPLETED);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix.

Other changes are just refactoring and testing.

}

@Test
public void invokedWithSteps() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a failing test.

@gfx
Copy link
Member Author

gfx commented Oct 29, 2018

@k-kagurazaka Can you review it, please?

@gfx
Copy link
Member Author

gfx commented Oct 29, 2018

Oops, some tests fail because of this change. Will fix them soon.

@@ -170,11 +177,11 @@ public void run() {
}
}
runTasksInTransaction(db, tasks);
saveStep(db, newVersion, MIGRATION_COMPLETED);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix.

It means to always update DB version (i.e. db.setVersion) via saveStep.

@@ -151,7 +151,7 @@ public void testIdempotenceWithNop() throws Exception {
public void upgradeFull() throws Exception {
migration.upgrade(db, 1, 100);

assertThat(migration.fetchDbVersion(db), is(16));
assertThat(migration.fetchDbVersion(db), is(100));
Copy link
Member Author

@gfx gfx Oct 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because migration.upgrade(db, 1, 100) is called the line before, the db version must be 100. The assertion was my mistake!

@gfx
Copy link
Member Author

gfx commented Oct 29, 2018

Everything is green.

@gfx gfx changed the title add failing tests for #436 Fix #436: ManualStepMigration not working Oct 29, 2018
@k-kagurazaka
Copy link
Member

#436 still happen after this fix.
The point of this issue is that Orma uses SchemaDiffMigration as the default migration engine ( this line ).
So ManualStepMigration#start is never called and database version stays 0 until users add a migration step.

@gfx
Copy link
Member Author

gfx commented Oct 29, 2018

OMG. You are right! Orma has to use OrmaMIgration by default even if no migration step is defined.

@gfx
Copy link
Member Author

gfx commented Oct 29, 2018

@k-kagurazaka The actual failing test is 74e6411, which is fixed at c36a3c7. What do you think of it?

Copy link
Member

@k-kagurazaka k-kagurazaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! LGTM 👍

@gfx
Copy link
Member Author

gfx commented Oct 29, 2018

@k-kagurazaka Thank you for the review. It's a nice day!

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

Successfully merging this pull request may close these issues.

ManualStepMigration is ignored at the first time (i.e. when DB version is 0)
2 participants