Search code examples
react-nativerealm

What happens to a Realm database when you update an iOS and Android apps built with React Native?


Currently I have an iOS and Android app with a DB powered by Realm. Right now I set use Realm importing a file named Realm.js which exports a Realm database with a schema loaded up.

Soon I will release an update to edit some fields in the Realm DB but if users update the app since the iOS and Android will download and install a new version, does the Realm schema version get reset?

In other words if a user updates an iOS or Android app with Realm will the old Realm database get persisted on the device and the new migrations from the update run?

Also is it possible to completely reset a Realm database? By that I mean destroying the old one and loading the first version of the schema, edited without having to write new migrations.


Solution

  • If your realm files are written to the Documents directory (the default) then when an update is downloaded, the updated app with access the existing Realm files and the schema version will still be at the last set version.

    If you would like to avoid migrations all together you can delete all realm and related files and directories before opening your new realm.