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
Allow configuring a Realm file to be deleted when a migration is required #1692
Comments
@pronebird we're going to be introducing the concept of an |
I'm not sure I like the idea of specifying this in |
That would require increasing the schema version and defining a migration block, which I don't think would serve the needs prompting users to ask for this. As much as I'd like to discourage the behavior of deleting realms on schema mismatch, the truth is that users are already finding hacky and dangerous ways to do this (try/catch block around first |
Just to chime in, as we're running into this too. Currently our use case is for alpha/beta versions of an app in development. We'd prefer not to bother with migrations every time we change the schema in a non-production app. Additionally, our use of Realm is as a persistent local cache that can be re-created if necessary. I understand discouraging the behavior of deleting realms on schema mismatch, but it's also definitely useful to have deleting the realm as an option of last resort if a migration goes south for some reason. We do a similar thing with Core Data in another app, and although it's considered the "nuclear" option, it's better than crashing at every startup. |
#1723 is now pending review, which should enable safely deleting a realm file on schema mismatch. |
That's still our preferred direction, but no one on our team is actively working on it at the moment. However, since this functionality can be built entirely at the Objective-C level, it's actually a task anyone from the community could contribute to Realm, if you're looking to get involved. We're currently quite involved with fine-grain notifications, KVO, cascading deletes, thread handover and preparing an official release with functionality that recently landed in master. |
I just might. |
This will be trivial to implement via |
How do we implement this in Swift 2.0? |
Read that before. If I may ask, where do we inject that line? From: Mark Rowe notifications@github.com notifications@github.com Using Realm.Configuration.deleteRealmIfMigrationNeeded
|
@shfishburn you pass a |
Here is how to use it. Thumbs up if did help. didFinishLaunchingWithOptions {
let configuration = Realm.Configuration(deleteRealmIfMigrationNeeded: true)
Realm.Configuration.defaultConfiguration = configuration
do { _ = try Realm() } catch {}
} RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
config.deleteRealmIfMigrationNeeded = YES;
config.schemaVersion = 2;
[RLMRealmConfiguration setDefaultConfiguration:config];
[RLMRealm defaultRealm];
NSLog(@">>> Realm path: %@", [config fileURL]); |
I have a cache storage which is ok to be wiped on schema changes. I don't want to migrate it since it's transitory anyway. Is there any way to nuke my realm when schema inconsistency found? This would also help a lot during development when schema changes occur pretty often.
I found a workaround but that requires a version bump, which I can probably simulate by using bundle version. What would be the official way? :)
The better option I found is to nuke realm when things go south:
The text was updated successfully, but these errors were encountered: