realm-swift
realm-swift copied to clipboard
Support renaming tables in migration
As originally requested here: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/realm-cocoa/sLd7S-jSX40/FeQSRPW0BwAJ
This could be exposed as -[RLMMigration renameModelFrom:(NSString *)oldName to:(NSString *)newName], which would use core's Group::rename_table() function.
Is there a workaround to rename a class that works with the current version of RealmSwift?
Based on the ObjC example, I've created this configuration:
let config = Realm.Configuration(
schemaVersion: 2,
migrationBlock: { migration, oldSchemaVersion in
if (oldSchemaVersion < 2) {
migration.enumerate("Person", { (oldObject, newObject) in
if let oldObject = oldObject {
print(oldObject)
migration.create("Employee", value: oldObject)
}
})
}
})
This does print the first oldObject, but it crashes on the migration.create with the unhelpful error message: libc++abi.dylib: terminating with uncaught exception of type NSException
Update: I've noticed that the crash is due to one of fields being an (optional) RealmObject. If I nil that out, it doesn't crash.
it crashes on the
migration.createwith the unhelpful error message:libc++abi.dylib: terminating with uncaught exception of type NSException
This is only unhelpful if you choose to ignore the exception message. From your update to your comment, it seems like your two classes may have different schemas?
Ah, I didn't know you could catch NSExceptions in Swift, but I got it to work.
This is the error that occurs: Error Domain=RLMException Code=0 "(null)" UserInfo={RLMRealmVersion=2.0.3, RLMRealmCoreVersion=unknown}
The only change I made to the schema is renaming the Object. Person to Employee, in this example.
Any plans to support this on the roadmap?
@marchy #2499 has been closed. I think this has been delayed.
It's been already implemented.. So simple to be added, but still not merged. :(
TOP
So is this available yet or still not merged in? Been a few years now...
Another 4 years have passed, is there any update on this feature?
It's as easy in Android as:
schema.rename("A", "B")
Very frustrating we cant do this for iOS
@mattlewer Realm is now dead, there won't be such a feature unless you contribute it yourself
@aehlke How do you mean it's dead, last release was 2 weeks ago?
@mattlewer it's recently deprecated and will not receive any more commits or releases from parent company later next year. it's transitioning to an open source framework without any parent company supporting it. there's been very little community contribution until now so I don't expect it to become very active after Mongo step down.