0

I had a question regarding adding modules to a realm configuration to restrict a Realm to only contain a subset of classes. I understand that it can be done by defining a custom RealmModule and then specifying that module in the realm configuration.

The scenario that I am facing right now is that I already have two realms (say Realms A and B) defined in a production version of my chatting application. Realm A stores the data that is fetched from my REST server and Realm B stores the data corresponding to chat threads. I have 12 model classes in my app. 11 out these 12 models are used to store the REST server data while the remaining 1 model is used to store the chat thread data.

Until now I was not aware that it is possible to restrict the models that one could include in a schema for a particular Realm using the RealmModule class. So currently, my production app has two Realms with all the 12 models being used in the schema of both the realms. In the next version of my app, I have made some changes to a couple of models that correspond to the REST data and have written migrations to address these changes. The issue that I am facing now is that even though I have only changed the models corresponding to the REST data, I have to provide the migration for the REST realm and the chat thread Realm because the schema for both the realms contain all the classes.

I am adding the code that I use to instantiate realm configurations in my production app and my current dev version after including the RealmModule

My production code:

       RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(mContext)
                .name(realmName + ".realm")
                .schemaVersion(DB_SCHEMA_VERSION)
                .encryptionKey(byteKey)
                .build();

Code after adding the RealmModule:

   RealmConfiguration restRealmConfiguration = new RealmConfiguration.Builder(mContext)
            .name(realmName + ".realm")
            .modules(new RestRealmModule())
            .schemaVersion(REST_DB_SCHEMA_VERSION)
            .migration(new RestDBMigration())
            .encryptionKey(byteKey)
            .build();

My question is that can I safely create two RealmModule classes, one including all the REST model classes and one including the chat thread model class and deploy these changes without causing any issues in the process of transitioning from my current production app to this new version?

How will Realm handle the already existing .realm files (containing all the models in the schema) on the production when I deploy a new version of the app that specify RealmModules restricting the realm schema to only deal with a subset of all the model classes?

If my approach is not correct then can someone please explain how should I be addressing this issue?

Thanks.

rbing
  • 133
  • 1
  • 10
  • 1
    Restricting a Schema later should work just fine. We only check that that types defined in the schema exists. We do not prevent other types also being present. – Christian Melchior Oct 28 '16 at 09:53
  • @ChristianMelchior Thanks for your prompt reply. I really appreciate it. – rbing Oct 28 '16 at 16:43

0 Answers0