I\'m using realm.io in a swift app. This is the first time I\'ve had to run a migration since I have an app in production. I changed one of the models and added a couple of
This works as intended, throwing exceptions when the downgrading (if working with branches where the versions differ) etc. Some sample migrations are shown too.
Realm.Configuration.defaultConfiguration = Realm.Configuration(
// Update this number for each change to the schema.
schemaVersion: 4,
migrationBlock: { migration, oldSchemaVersion in
if oldSchemaVersion < 2 {
migration.enumerate(SomeObject.className()) { oldObject, newObject in
newObject!["newColumn"] = Enum.Unknown.rawValue
}
}
if oldSchemaVersion < 3 {
migration.enumerate(SomeOtherObject.className()) { oldObject, newObject in
newObject!["defaultCreationDate"] = NSDate(timeIntervalSince1970: 0)
}
}
if oldSchemaVersion < 4 {
migration.enumerate(SomeObject.className()) { oldObject, newObject in
// No-op.
// dynamic properties are defaulting the new column to true
// but the migration block is still needed
}
}
})
Obviously that won't compile as is with the SomeObject etc., but you get the idea :)