Skip to content
This repository was archived by the owner on Jul 22, 2026. It is now read-only.

Reset database if version is 0.9.18 - #4503

Merged
cammellos merged 1 commit into
developfrom
bug/#4409
May 29, 2018
Merged

Reset database if version is 0.9.18#4503
cammellos merged 1 commit into
developfrom
bug/#4409

Conversation

@cammellos

@cammellos cammellos commented May 29, 2018

Copy link
Copy Markdown
Contributor

fixes #4409

Summary:

The code will try to open an encrypted realm.
If it fails will try to open an unencrypted realm.

If that is successful we reset the database and create an encrypted version.

We ensure it is unencrypted as we don't want to reset the database if a IO error occurred on step 1.

Testing notes (optional):

Should ask you to reset from 0.9.18, but update cleanly from 0.9.19/nightlies

status: ready

@cammellos cammellos self-assigned this May 29, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you detail this function? Not sure how version and encryption are related.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We are just trying to open the file, to make sure it is unencrypted, basically we only care if it's successful or not.

@jeluard jeluard May 29, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I can think of others reason for this call to fail than just being unencrypted. Maybe we can find a better name? Or a safer method?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we improve error handling? What if this fails ?
(I realize you didn't introduce this)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In this case it's ok for us to fail, we want to detect unencrypted versions of realm, so we can reset them, once we remove the code I agree error handling should be made more robust.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about returning nil only and not logging then?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you mean just remove the log statement? (we need the schema version if it we manage to decrypt it)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Right in the catch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hopefully this function does not only return nil 😅

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this not be called outside of reset?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not sure, it used to be there I have reintroduced it ( it seems resetting realm is a single purpouse thing, only applies for this release, should be throwaway code), but don't mind putting it outside.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We might find other needs for this in the future. I would not expect that kind of side effects when calling a reset function.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What will happen if this is fresh install without any previous schema - won't unencrypted? be true ?
If yes, will it work fine, or crash on the reset-realm schema (+ show confusing pop-up) ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

that's interesting, it seems like you are right, I had tested it on my local android and worked fine, but will make sure it works.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Weirdly enough it just works, I can't really say why from the code (possibly because opening an empty realm will succede and return a version of 0? ). But will make sure that is the case ,good shout.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, opening an empty realm does not fail, and return a schema version of -1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually I know why, calling version on empty realm returns -1, I just remembered. It's probably worth documenting somewhere...

@rasom

rasom commented May 29, 2018

Copy link
Copy Markdown
Contributor

@jeluard

jeluard commented May 29, 2018

Copy link
Copy Markdown
Contributor

Can we take this opportunity to add some simple doc to realm function? This would help improving the overall quality of this ns that requires some love :)

@rasom

rasom commented May 29, 2018

Copy link
Copy Markdown
Contributor

@cammellos

Copy link
Copy Markdown
Contributor Author

@jeluard yes, I will test everything works ( is still wip, I needed an image to test on a real device), and add some docs to the namespace

@cammellos
cammellos requested a review from mandrigin May 29, 2018 07:58
@cammellos

Copy link
Copy Markdown
Contributor Author

@jeluard updated with docstrings and some tests

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is it fine to call migrate-schemas if encrypted-version is -1?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I believe so, I haven't changed that logic + I have tested multiple times on clean installations

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would add a comment though, because it looks like this case with -1 was just forgotten.

@mandrigin mandrigin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@jeluard

jeluard commented May 29, 2018

Copy link
Copy Markdown
Contributor

@cammellos Awesome thanks for the effort!

@rasom

rasom commented May 29, 2018

Copy link
Copy Markdown
Contributor

@rasom

rasom commented May 29, 2018

Copy link
Copy Markdown
Contributor

@lukaszfryc

Copy link
Copy Markdown
Contributor

@cammellos all looks good 👍
I tested upgrading from 0.9.18 (Android, iOS) as well as from develop (iOS). I also checked some scenarios around it like recovering account, creating additional new account, etc.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
@cammellos
cammellos merged commit 26dd1c1 into develop May 29, 2018
@rasom
rasom deleted the bug/#4409 branch May 30, 2018 09:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

"Realm file decryption failed" error after app upgrade from release 0.9.18 to develop version

6 participants