Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Convert the WellSqlConfig migrations to Kotlin#1395

Merged
aforcier merged 18 commits intodevelopfrom
0nko/kotlin-migration
Oct 16, 2019
Merged

Convert the WellSqlConfig migrations to Kotlin#1395
aforcier merged 18 commits intodevelopfrom
0nko/kotlin-migration

Conversation

@0nko
Copy link
Copy Markdown
Contributor

@0nko 0nko commented Oct 2, 2019

After fixing #1393, I've been thinking about how to make the migrations safer and less error-prone. I've converted the WellSqlConfig class to Kotlin and extracted some repetitive code, which should help. What do you think?

I've copied over the SQL scripts but just to be safe, I'd like to ask the reviewer to double check that everything correct.

@0nko 0nko added the Core label Oct 2, 2019
@0nko 0nko requested review from aforcier and oguzkocer October 2, 2019 09:18
@oguzkocer oguzkocer self-assigned this Oct 8, 2019
Copy link
Copy Markdown
Contributor

@oguzkocer oguzkocer left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @0nko. I have gone through every single migration and everything seems to be in order except for a single case that seems to be missing the migration. I haven't done a character by character comparison, but I did look through each case from before the change and after it and all of it looked the same. Due to the sensitivity of this PR, I'd suggest at least another dev to look at it, possibly even more, just to be on the safe side. Let me know what you think!

Comment thread fluxc/src/main/java/org/wordpress/android/fluxc/persistence/WellSqlConfig.kt Outdated
@aforcier
Copy link
Copy Markdown
Contributor

Just came by to mention that the unit tests and ktlint were failing but it looks like you fixed them 👍

Nice Kotlinification, this much improves the class 🎉.

Other than lint/tests and Oguz's notes this looks good. One thing is that the checkstyle plugin is unhappy with this file and riddles it with newline warnings in the IDE (the actual gradle task passes). Are you seeing that too?

Also for testing, I was wondering @0nko @oguzkocer if you've tried running a migration? Something like:

  1. Run really old build of WPAndroid and WooAndroid
  2. Login, fetch some posts, etc
  3. Build current version of each app using this PR's FluxC hash
  4. Run app, check the log for long series of migrations as expected
  5. Make sure everything still works

It's probably fine but let's be extra cautious with our migration scripts. I'll try to try this today, if not it'll be next week.

@oguzkocer
Copy link
Copy Markdown
Contributor

@aforcier I think that's a good idea. I hope the old builds will work fine with the new hash, I know it should, but with Gradle it's not always the case.

@0nko I see some new commits, can you let me know when it's ready for another pass/test?

@aforcier
Copy link
Copy Markdown
Contributor

@aforcier I think that's a good idea. I hope the old builds will work fine with the new hash, I know it should, but with Gradle it's not always the case.

Right - my suggestion was to use old releases, that way they're already compiled and we don't have to worry about being able to build them. Downside is not debuggable, but that's only an issue if there turns out to be an actual problem 😀 (then we'd need to dig in)

@0nko
Copy link
Copy Markdown
Contributor Author

0nko commented Oct 11, 2019

@aforcier @oguzkocer Thanks for the review!

I've spent half a day yesterday trying to make the migration run from version 1 work. I found a point where the WellSqlConfig was just added and made it build: 0nko/fluxc-db-v-1. There were a couple of missing create table scripts but it works fine now. It was a bit tricky, though, because for each I needed a version of the table in a specific point in history.

I also wanted to write a unit test that would run the migration the same way automatically but I haven't figured out how to make it work yet.

I've performed some basic testing and things seem to be working.

@oguzkocer You can go ahead with another pass. If I'm able to make the unit test work, we can add it later.

@0nko 0nko requested a review from oguzkocer October 11, 2019 08:05
Copy link
Copy Markdown
Contributor

@oguzkocer oguzkocer left a comment

Choose a reason for hiding this comment

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

Thanks for the updates @0nko! I compared the migrations again, this time I didn't do all of it, but instead just compared about 30% of it. Everything looked good to me.

I also installed 2 old builds, one very old, one about 1 year old and then updated it with the apk built with the changes (thanks to @jkmassel 🙇 ) and in both cases the migration worked fine and my data (posts, pages & comments) was preserved.

I think we can 🚢 it but I'd feel better if @aforcier could also take another look with how important migrations are.

@oguzkocer oguzkocer removed their assignment Oct 11, 2019
@0nko 0nko requested review from aforcier and removed request for aforcier October 15, 2019 09:17
@0nko
Copy link
Copy Markdown
Contributor Author

0nko commented Oct 15, 2019

@aforcier, would you mind taking another look? I think it should be good, but just in case. :)

@aforcier
Copy link
Copy Markdown
Contributor

I tested migrating (to a build using the tip of this branch) from a few older WPAndroid versions and one WooAndroid version:

  • WPAndroid 7.0, DB version 4
  • WPAndroid 9.6, DB version 25
  • WooAndroid 1.1, DB version 48

In all cases the migrations ran and were logged correctly, and drafts/data seemed to be preserved.

There's a small problem though - this currently is a breaking change for WPAndroid (in debug but not in release) and WooAndroid (any build). The breaking classes are WPWellSqlConfig and WooWellSqlConfig. There are two causes:

  1. The constructors now require Context and a Context? is being supplied.
  2. The second reset() function that accepted a helper: WellTableManager was removed

@oguzkocer
Copy link
Copy Markdown
Contributor

Ah yes, I saw those breaks as well in WPAndroid, but didn't think it would be big deal. I should have mentioned it though since we want to have PRs ready to be merged when this change is merged to develop. Thanks for bringing it up @aforcier!

@0nko
Copy link
Copy Markdown
Contributor Author

0nko commented Oct 15, 2019

Thanks for pointing it out, Alex! I added the original reset method with the helper parameter, which was needed for the downgrades. I've created a PR in each repo, ready for review/merge.

@aforcier
Copy link
Copy Markdown
Contributor

Looks good and so do the counterpart PRs - merging this and leaving the Woo and WP PRs open so you can update the tag before those merge.

:shipit:

@aforcier aforcier merged commit e1b94df into develop Oct 16, 2019
@aforcier aforcier deleted the 0nko/kotlin-migration branch October 18, 2019 12:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants