Android Realm Migration version number based on what?

I am doing my first migration to Realm and started thinking about the version number. What is this version based on?

Because if it is based on what is on your phone, how do I handle it if a new person installs the application and receives migration? Because it will also update fields that are already set due to a new installation.

+4
source share
2 answers

Kingdom Christian is here. The migration API is still in a very experimental state and looks pretty ugly, so now the version number always starts at 0, and the only way to change this is to migrate.

, , 0, - :

   // Pseudo code
    public class RealmHelper() {

        private static SharedPreferences prefs;

        public static Realm getInstance() {
            if (!prefs.getBoolean("versionSet", false)) {
                String path = new File(context.getFilesDir(), Realm.DEFAULT_REALM_NAME).getAbsolutePath();
                Realm.migrateRealmAtPath(path, new RealmMigration() {
                            @Override
                            public long execute(Realm realm, long version) {
                                return 42; // Set version numbers
                            }
                        })
                prefs.edit().putBoolean("versionSet", true).apply();
            }

            return Realm.getInstance();
        }
    }

: https://github.com/realm/realm-java/pull/929

+7

Realm 0.84.2 (. API), (0.84.2) - , :

  • version 0, db . , , schemaVersion , .

  • schemaVersion , 3, , , schemaVersion 3, , . , SharedPreferences.

  • , , ,...

  • , convertColumnToNullable

+2

All Articles