简体   繁体   English

领域迁移时获取过去的数据库数据

[英]Getting past db data when realm migration

I have used realm database(iOS and Android both). 我已经使用了领域数据库(iOS和Android都使用)。 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. 只是为了确认,您已经成功地通过Realm在应用程序的iOS和Android版本上执行了架构迁移,但是您的问题是,是否可以从旧架构版本的表中提取数据并将其移至新版本您最新的架构版本中的表格。 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. 执行迁移时,您可以在MigrationBlock块/ RealmMigration对象内运行循环,以将数据从旧表手动复制到新创建的表中。

Examples of this logic can be found in the sample code of both the iOS and Java repositories on Realm's GitHub account. 可以在Realm的GitHub帐户上的iOSJava存储库的示例代码中找到此逻辑的示例。

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. 不幸的是,一旦在Realm文件上完成了迁移并且删除了先前的表,那么以后就无法回溯和提取数据。

You could do something like this: 您可以执行以下操作:

RealmSchema schema = realm.getSchema();

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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