Data migrations in the Kotlin SDK #906
Replies: 3 comments
-
For anyone stumbling upon this, an |
Beta Was this translation helpful? Give feedback.
-
Hi guy, |
Beta Was this translation helpful? Give feedback.
-
Hi Guys. We are in the middle of migrating from Java-sdk to the Kotlin-Sdk. In the Java-sdk we have a lot of migration blocks which are checking the old version of the schema and based on it certain modifications are done. Let's say we are at schema version 3, prior to migrating to the Kotlin-sdk and once we updated the dependencies part, we increment the schema version to 4. When the app is run, after switching to the Kotlin-sdk, I see that the oldRealm.configuration.schemaVersion is directly 4 but I expected to be 3, so I apply certain modifications like switching from Date to RealmInstant to few properties. This means that the code that should be executed if schemaVersion == 3 is skipped. Any ideas why this happens? Am I missing an important detail when it comes to switching from Java-sdk to Kotlin-sdk? |
Beta Was this translation helpful? Give feedback.
-
Hello! Thanks for providing the new Kotlin SDK. While working on an exemplary migration from the previous Java SDK, I've been running into some trouble while trying to understand the new way of using
RealmMigration
.tl;dr: How do you write structural migrations?
In the Java SDK, it was necessary to declare any structural changes, including the addition of new tables and updates to existing ones, inside an
io.realm.RealmMigration
. Therefore, our existing project has a bunch of statements that we would need to migrate, for example (not actual code, but similar in nature):How does this work with the Kotlin SDK and
AutomaticSchemaMigration
? I understand how to do the conditionals, since those are available via theMigrationContext
given to the new method. However, I can't seem to figure out how to deal with the addition of tables and deletion of columns. For example, is it no longer required to declareDbTransaction
at all? If so, then how are we supposed to deal with app migrations correctly? Which part exactly is taken away by the automatic portion ofAutomaticSchemaMigration
?Looking forward to some insight from @cmelchior. Thank you in advance 🙇♂️
Beta Was this translation helpful? Give feedback.
All reactions