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

Added missing migration methods #2635

Merged
merged 16 commits into from
Sep 29, 2021
Merged

Added missing migration methods #2635

merged 16 commits into from
Sep 29, 2021

Conversation

papafe
Copy link
Contributor

@papafe papafe commented Sep 21, 2021

This PR adds two methods that were missing on Migration: RemoveType and RenameProperty.

Description

Fixes #2543

TODO

  • Changelog entry
  • Tests (if applicable)

@papafe papafe requested review from nirinchev, DominicFrei and LaPeste and removed request for nirinchev September 21, 2021 11:06
@papafe papafe marked this pull request as ready for review September 21, 2021 11:06
}

return true;
}

/// <summary>
/// Removes a type during a migration. All the data associated with the type, as well as its schema, will be removed from <see cref="Realm"/>.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to differentiate between the (general) schema and the object schema to not confuse anyone here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's clear enough with the "its", but maybe it's not?

Copy link
Contributor

Choose a reason for hiding this comment

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

Clear enough for me because I know how Realm works and what the difference between a schema and an object schema is. Then again, how important is this for a user? They just want to use the framework and not understand too much about the internals I suppose. I guess it's fine both ways. ;)

Copy link
Contributor

@DominicFrei DominicFrei left a comment

Choose a reason for hiding this comment

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

Don't see anything wrong with that. :) Just added two questions for clarification.

@papafe
Copy link
Contributor Author

papafe commented Sep 21, 2021

A question is... Do we want the two method to work in the same way for what regards using a type that is not in the schema?
RemoveType will return false, while RenameProperty will likely throw an exception. I suppose the reason why it was done for the first and not for the second in Cocoa (where I took inspiration) is because for the first method we need to retrieve the table anyway to execute the method.

@nirinchev
Copy link
Member

Removing a type that no longer exists (or never existed) is probably not an exception-worthy situation. You do end up in the same state - a Realm without this particular type. Renaming a property that didn't exist vs one that did exist is different as you would expect to have some data appear in your new Realm - that's the main point of using RenameProperty vs just deleting the old one and adding the new one. So if it turns out you're trying to rename something non-existent, that's likely a mistake and we should let you know.

@DominicFrei
Copy link
Contributor

The non-throwing delete would also be in line with other deletes. Take DeleteRealm for example. If the Realm was already deleted, it's fine, we just accept that because the goal was that that Realm does not exist anymore. Throwing an exception would be like throwing an exception just because the Realm we try to delete did not exist in the first place.

Copy link
Member

@nirinchev nirinchev left a comment

Choose a reason for hiding this comment

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

I have a couple of comments mostly around code style and docs, but for the most part it looks good. What is missing outside of the comments I added is:

  1. Tests for invalid arguments (null, empty strings, a string with 1000 characters)
  2. A test for renaming a property to a value that doesn't exist in the new schema
  3. Address the build warnings/CodeQL errors

@nirinchev
Copy link
Member

Can you rebase on master? There was a Coveralls outage over the weekend which is why the base coverage report is missing.

@coveralls
Copy link

coveralls commented Sep 24, 2021

Pull Request Test Coverage Report for Build 1286514500

  • 17 of 17 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.05%) to 74.388%

Totals Coverage Status
Change from base Build 1271688483: 0.05%
Covered Lines: 4582
Relevant Lines: 6142

💛 - Coveralls

@papafe
Copy link
Contributor Author

papafe commented Sep 24, 2021

Final corrections done (lint correction, more tests, ...)

Copy link
Member

@nirinchev nirinchev left a comment

Choose a reason for hiding this comment

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

Good job!

@papafe papafe merged commit 9006b89 into master Sep 29, 2021
@papafe papafe deleted the fp/2543-add-migration-methods branch September 29, 2021 12:42
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add missing methods to migration
4 participants