Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

oldVersion, newVersion and schemaVersion in Realm migration?

I'm confused about these versions.

In document:

  • oldVersion - the schema version of the Realm at the start of the migration.
  • newVersion - the schema version of the Realm after executing the migration.

  • schemaVersion(long schemaVersion) - Sets the schema version of the Realm.

Is schemaVersion will be newVersion and why do we need ++oldVersion when migrate?

Migration Example

like image 780
ke.np Avatar asked Jul 18 '26 13:07

ke.np


1 Answers

oldVersion is the version of the Realm file when starting the migration. New version is the expected version when done with the migration, which is equal to the number you provide in schemaVersion().

The reason for doing oldVersion++ is that it is an easy way of doing stepwise migrations that will work no matter which version you upgrade from. The code will automatically skip the steps not needed.

You can read more about migrations here as well: https://realm.io/docs/java/latest/#migrations

like image 181
Christian Melchior Avatar answered Jul 21 '26 03:07

Christian Melchior



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!