Uploaded image for project: 'Realm Cocoa SDK'
  1. Realm Cocoa SDK
  2. RCOCOA-1680

Auto migration kills linear migration and should be optional (or removed).

      Problem

      if oldSchemaVersion < 8 {
          migration.enumerateObjects(ofType: "UserContact") { oldObject, newObject in
              newObject!["displayName"] = oldObject!["firstName"] + " " + oldObject!["lastName"]
          }
      }
      
      if oldSchemaVersion < 9 {
          // 'UserContact' is removed, 'Contact' is introduced
          migration.enumerateObjects(ofType: "UserContact") { oldObject, newObject in
              let contact = migration.create("Contact", value: [
                  "id": UUID().uuidString.lowercased(),
                  "firstName": oldObject!["firstName"] as? String ?? "",
                  "lastName": oldObject!["lastName"] as? String ?? "",
                  "displayName": oldObject!["displayName"] as? String ?? "",
              ])
          }
          migration.deleteData(forType: "UserContact")
      }
      

      Coming from a schema version < 8, the migration to schema version 8 fails because there is no UserContact type anymore and newObject is nil.

      At first glance the auto migration looks nice and handy but it is a total time consuming and error prone mess if you have to validate and fix all previous migration steps whenever a new schema version is introduced. Indeed it makes it nearly impossible to have a linear migration.

      I also have an android app running where all migration steps and schema changes have to be done manually. Therefore there is no problem with linear migration. The current migration step is a bit more complex but it is "write once and forget". I cannot understand why there is no such thing in the swift sdk.

      Currently i am at schema version 9. I don't even want to think about when i'm at schema version 100 and have to check all previous migration steps every time a new schema version is introduced.

      Please add a feature to be able to disable automatic migration and to do exactly the same than in android . This would also remove the need to develop different migration logic for iOS and android.

      Solution

      No response

      How important is this improvement for you?

      Dealbreaker

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: