Realm-cocoa: Use default property values when adding a new column in a migration

Created on 24 Apr 2015  路  12Comments  路  Source: realm/realm-cocoa

P-2-Expected T-Bug

Most helpful comment

Any solution or fix to this issue?

All 12 comments

This one bit me as well. Is there any timeframe on this or would it maybe be an idea to note it in the migration documentation?

I just added this to our docs: https://realm.io/docs/objc/latest/#migrations

Note that default property values aren't applied to new objects during migrations. We consider this to be a bug and are tracking it as #1793.

I hope this will be fixed soon as it's difficult for the developers to test if the migrated DB works for each of the previous versions of the realm. (after 90 updates in our case)

We recently received errors because of unexpected null string properties (with normally a default value of @""), when we released a major update of our app.

The challenge here is to only ever set default values if they haven't explicitly been set by a user, which in turn requires tracking which setters were invoked.

This does seem challenging. I would imagine if a user explicitly set a properties value back to the default, it should not be automatically migrated if the default changes. It almost seems that there ought to be some sort of resetProperty: method.

EDIT: I just realized that this issue only pertains to new columns, which simplifies it.

@jpsim Couldn't we also strictly set the default values _before_ the user sets the property?

Yes, I think eagerly setting default values before user set the property would be acceptable. It _shouldn't_ have a significant performance impact, but I'd prefer if we checked nonetheless.

So what is solution for assigning default value for new Column after migration ? any magical method ?

No magic. Set manually :(

setting manually (reference)
https://realm.io/docs/swift/latest/#updating-values

Any solution or fix to this issue?

Still happens here, any progress on this?
Please, pretty PLEASE :-)

Was this page helpful?
0 / 5 - 0 ratings