A local database in a mobile app — migrations, data loss and abandoned Realm

Why after an update the app crashes only for some users or wipes their data, how to check migrations in an app you took over, what about Realm, Isar and Hive, and how much changing the database library costs.

Zespół Mobilesoft· Engineering team· 2 grudnia 2026· 8 min czytania

The new version of the app passed testing, store review and runs fine on the team's phones. After the release, reports come in: for some users the app closes right after launch, others write that their saved data has disappeared. The common factor is found quickly — only people who updated from an older version are affected. Fresh installs work flawlessly, so the tests caught nothing.

This is a typical symptom of a badly handled local database migration. In apps taken over from another team it is a common risk, because nobody remembers how the data structure on the phone has changed. On top of that, some popular database libraries are no longer developed. In this article we describe what to check in an existing app, how to change the data structure safely and what to do when the database library has been abandoned.

What the app stores on the phone

Almost every app keeps something locally. Usually there are four kinds of data:

  • A database — Room or SQLite on Android, Core Data or SwiftData on iOS, and in cross-platform apps Realm, Drift, Hive, Isar or WatermelonDB. This holds lists, history and data for working offline.
  • Key–value settings — SharedPreferences and DataStore on Android, UserDefaults on iOS, AsyncStorage or MMKV in React Native.
  • Files — photos, documents, downloaded content, cache.
  • Secure storage — Keychain on iOS and Keystore on Android, usually for sign-in tokens.

The most important question is: which data exists only on the phone? If everything can be downloaded again from the server, losing the local database is annoying but not a disaster. If users have notes, draft orders, measurements or data collected offline that are not on the server, every migration bug means that data is lost for good.

Why migrations break in older apps

  • Users skip versions. Some people update from a version that is a year or two old. The migration has to go through all the changes in order. One missing step is enough for the app not to start for those users.
  • Tests only cover a fresh install. On a tester's phone the database is created from scratch, so the migration never runs.
  • Silent data deletion. On Android, Room crashes the app by default when a migration is missing. A developer who wants to "fix it quickly" enables fallbackToDestructiveMigration — the app stops crashing, but deletes the database whenever a migration is missing. The user loses data and nobody finds out.
  • No history of the database structure. If the project does not save the schemas of successive versions (in Room this is what exportSchema is for), you cannot later write or test migrations from older versions.
  • A library update changes the data format. A new version of a database library may require converting the database file. This is a risk with every major update, which we describe in the article on updating an old Flutter or React Native app.
  • Restoring a backup. On reinstall, Android can restore database files from the Google backup (auto backup covers up to 25 MB of app data), and iOS restores app data from an iCloud or computer backup. The new version of the app then receives the database from the old one and has to migrate it.

How to check the database in an app you took over

  1. List what the app uses — the database library and its version, settings, files, Keychain and Keystore.
  2. Establish which data exists only on the phone. This determines how much a bug costs.
  3. Check the database version number and the list of migrations. Is there a migration for every step? Are the schemas of previous versions in the repository?
  4. Look for destructive workarounds — fallbackToDestructiveMigration, deleting the database file on error, deleteRealmIfMigrationNeeded in Realm.
  5. Check which versions users update from. Data on the app versions in use comes from analytics — more in the article on analytics for maintenance decisions.
  6. Test the update from the oldest version in use on realistic data, not just a fresh install.

Abandoned and deprecated database libraries

Library Status What it means Realm with Device Sync (MongoDB) Device Sync and Atlas Device SDKs deprecated, end of life 30.09.2025 Sync with MongoDB's cloud does not work — data does not reach the server Realm as a local database Open source project maintained by the community Works, but development and fixes depend on the community Isar (Flutter) Original project abandoned by its author, community forks exist Risk with new versions of Flutter, Android and iOS Hive (Flutter) Original project no longer developed, popular hive_ce fork Switching to the fork is usually enough Room, SQLite, Core Data, SwiftData, Drift Actively developed No urgent need to change

The most urgent case is an app that used Realm Device Sync. If nobody reworked it, sync stopped working after 30 September 2025. Data saved since then may exist only on users' phones. Apps with local Realm, Isar or Hive still work, but every OS or framework update risks the library no longer compiling. We describe similar cases in the article on deprecated SDKs and APIs.

How to change the database structure safely

  • Save the schema of every version. Room exports them as JSON files that belong in the repository. Core Data has versioned models, and SwiftData has VersionedSchema and SchemaMigrationPlan.
  • Write a migration for every step, and leave simple changes to automatic migrations (Room @AutoMigration, Core Data lightweight migration).
  • Test migrations automatically. On Android, MigrationTestHelper is used for this. The test should go through the whole path: from the oldest supported version to the current one, on data resembling real data. How to start testing a project without tests is covered in the article on testing an old app.
  • Don't delete data silently. If a migration fails, log the error in your crash monitoring tool and — if possible — keep the old database for manual recovery.
  • Release in stages. A migration is one of the things you cannot undo by simply restoring the previous version. We write about this in the article on a faulty app update.

Changing the database library

Moving from Realm, Isar or an abandoned Hive to another solution requires moving users' data, not just replacing code. The safest approach looks like this:

  1. The new app version contains both libraries. On first launch it reads data from the old database and writes it to the new one.
  2. Verification. The app compares record counts and logs in analytics whether the transfer succeeded. The old database stays on the phone.
  3. A few versions later — when the data shows that practically all users have gone through the migration — you remove the old library and its files.

If the app needs sync (a replacement for Realm Device Sync), you also have to choose a solution: a ready-made sync service, such as PowerSync or Ditto, or your own API. We describe this in more detail in the article on offline mode in an existing app.

How much it costs

Sample estimates at a rate of PLN 180 net per hour:

Scope Time Net cost Review of local data and migrations in an app you took over 4–12 h approx. PLN 0.7k–2.2k Adding missing migrations and removing destructive workarounds 8–24 h approx. PLN 1.4k–4.3k Automated tests of migrations from older versions 8–20 h approx. PLN 1.4k–3.6k Moving from an abandoned library to a fork (e.g. Hive → hive_ce) 4–16 h approx. PLN 0.7k–2.9k Changing the database library with data transfer (e.g. Realm → Room / Core Data / Drift) 40–120 h approx. PLN 7.2k–21.6k Replacing Realm Device Sync with your own API or a sync service 80–240 h approx. PLN 14.4k–43.2k

The amounts are indicative and depend on the number of tables, how much logic relies on the database, the app's technology and the state of the backend. The rate is an example — we set the actual cost after reviewing the project.

Summary

The local database is a part of the app whose bugs only show up for users updating from older versions. In an app you took over, it is worth establishing which data exists only on the phone, checking the migration history and removing silent workarounds that wipe the database. If the app uses Realm Device Sync, sync has not worked since 30 September 2025 and needs to be replaced. Local Realm, Isar or Hive still work, but it is worth planning a move to a fork or another library before the next OS update forces it.

We review local data, handle migrations and replace libraries as part of mobile app maintenance, and when taking over a mobile app we check what the app stores on the phone. We replace sync with a custom API as part of our backend and API service. If you want to know whether the libraries and SDKs in your app are up to date, request a free app analysis or contact us.