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

Support renaming tables in migration #2491

Open
jpsim opened this issue Sep 7, 2015 · 12 comments
Open

Support renaming tables in migration #2491

jpsim opened this issue Sep 7, 2015 · 12 comments

Comments

@jpsim
Copy link
Contributor

jpsim commented Sep 7, 2015

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.

@tomlokhorst
Copy link

tomlokhorst commented Nov 4, 2016

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.

@jpsim
Copy link
Contributor Author

jpsim commented Nov 8, 2016

it crashes on the migration.create with 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?

@tomlokhorst
Copy link

tomlokhorst commented Nov 8, 2016

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.

@marchy
Copy link

marchy commented Aug 25, 2017

Any plans to support this on the roadmap?

@ricardopereira
Copy link

@marchy #2499 has been closed. I think this has been delayed.

@aleksey-ho
Copy link

It's been already implemented.. So simple to be added, but still not merged. :(

@mefilt
Copy link

mefilt commented Oct 28, 2020

TOP

@marchy
Copy link

marchy commented Oct 28, 2020

So is this available yet or still not merged in?
Been a few years now...

@DominicFrei DominicFrei self-assigned this Jan 22, 2021
@DominicFrei DominicFrei removed their assignment Apr 1, 2021
@sync-by-unito sync-by-unito bot changed the title Support renaming tables Support renaming tables in migration Sep 12, 2023
@mattlewer
Copy link

mattlewer commented Nov 4, 2024

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

@aehlke
Copy link

aehlke commented Nov 6, 2024

@mattlewer Realm is now dead, there won't be such a feature unless you contribute it yourself

@mattlewer
Copy link

@aehlke How do you mean it's dead, last release was 2 weeks ago?

@aehlke
Copy link

aehlke commented Nov 21, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants