Search code examples
react-nativerealm

What happens to a prebundled Realm file when an app gets updated?


I have a simple React Native application that's a dictionary app. It allows the user to bookmark a specific word and it's definition. So I have the two following models: Word and Bookmark.

Currently I have it so that the app opens a prefilled Realm database and obviously the Bookmark is model is empty.

  1. Let's say the user started using my app and added a word that they liked to the Bookmark.
  2. Then I release an update of the app with more words but I do so by updating the prebundled Realm file.

Will the updated Realm file remove all the 'Bookmark' that the user created since the prebundled Realm file has 'Bookmark' empty?

If so do I have to have add a second Realm file that stores the unique id of the word that the user bookmarked?


Solution

  • You are correct that if you overwrite the Realm file every time you update then any data written to that Realm will also be overwritten. You have a few options here. First is to store the bookmarks in a separate Realm file so that they aren't overwritten when you update your dictionary. The downside to this is a little extra code/performance hit to look up bookmarked items from the dictionary Realm.

    The second option is to copy individual dictionary entries into a single writable Realm on launch. This would result in a bigger performance hit at launch when updating to a new app version but would allow you to store bookmarks and entries in the same Realm file using object links.