新しいRealmObjectとパラメータを使用して、古いレルム構造を新しいレルム構造に移行しようとする問題に直面しています。つまり、アプリはすでにGoogle Playに入っているため、ユーザーは特定のデータをいくつかのテーブルに既に保存しています。目標は、レルム・データベースを削除して別の場所に保管する前にデータをリストアすることです。私は今何をすべきかについてのジレンマに陥っています。レルムのバックアップと新しいバージョンへの移行
これを解決しようとするが、私は私のApplicationクラスで次のように実装:
RealmMigration migration = new RealmMigration(){
@Override
public void migrate(...){
if(oldVersion == 0){
//Get the data from realm and store somewhere else
}
}
}
RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(this)
.schemaVersion(1)
.migration(migration)
.deleteRealmIfMigrationNeeded()
.build();
Realm.setDefaultConfiguration(realmConfiguration);
Realm.getInstance(realmConfiguration);
ここで問題にそれをやって、方法deleteRealmIfMigrationNeeded()が実行されると、移行が()、その後、ではないということですデータベースからデータを取得する前にすべてのデータが失われます。私が望んでいたのは、アプリケーションをアップデートするときにデータベースからバージョンを取得し、それが古いバージョンであるかどうかを比較し、レルムのデータをファイルに格納してから、deleteRealmIfMigrationNeeded()を実行してRealmMigrationNeededException。
私はすでに次のリンクを見て:
How to backup Realm DB in Android before deleting the Realm file. Is there any way to restore the backup file?
Realm not auto-deleting database if migration needed
https://github.com/realm/realm-cocoa/issues/3583