perwyl
perwyl

Reputation: 323

RealmSwift Unit Test For Realm.io Migration

I need to write unit case for realm.io migration. How do i simulate a before and after Object Class?

Upvotes: 3

Views: 956

Answers (1)

Edman
Edman

Reputation: 5605

One solution is to have a realm file previously saved (such as in your unit test bundle) with the schema version from which you want to test the migration. Your realm object in code is kept in its most recent version, while the realm schema in disk contains an older version.

Have a look at the migration sample app.

In the sample there are versions V0, V1 and V2 of the same Person object, as well as three different realm database files with different schema versions default-v0.realm, default-v1.realm and default-v2.realm.

The same migrationBlock is then used in all versions of the database to ensure it can correctly bring any possible old schema to the newest V2.

Upvotes: 3

Related Questions