简体   繁体   中英

Getting past db data when realm migration

I have used realm database(iOS and Android both). It worked well still now and migration. When migration, I could add table and additional columns in updated schema. By the way, I have no idea whether I'm capable of extracting previous table data and move to new schema table. Please let me know about this.

Just to confirm, you've successfully managed to perform a schema migration with Realm on both the iOS and Android versions of your app, but your question is whether you can extract data from a table in an older schema version and move it to a new table in your latest schema version. Is this correct?

If this is correct, then yes. At the time of performing a migration, you can run a loop inside your MigrationBlock block/ RealmMigration object to manually copy the data from an older table to a newly created one.

Examples of this logic can be found in the sample code of both the iOS and Java repositories on Realm's GitHub account.

Unfortunately, once a migration has completed on a Realm file and the previous table has been deleted, then it's not possible to back-track and extract the data at a later time.

You could do something like this:

RealmSchema schema = realm.getSchema();

schema.get("OldTableName").renameField("OldFieldName", "NewFieldName");

schema.rename("OldTableName", "NewTableName");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM