Firestore and Changing Document Models in an App

Viewed 29

So we have an app that interacts directly with Firestore. In both queries for documents, creates new documents, updates, listens for changes, etc.

So we have one version of our app live. The question becomes how we can modify the model in the database, for example, adding a non-optional field, without breaking the functionality of the current apps that are installed on people's phones.

All I can think of for now is to require to be on the latest version, or perhaps the latest without a breaking change, in order to log in to initialize firebase - by using a major.minor.patch, and update the major whenever there's a breaking change.

Is there a smoother way to do this? I am more familiar with the backend and web, so not sure what's considered a best practice in this case.

1 Answers

The simplest solution I can think of would be to add the version of the app into a document in the database, and each time you open the app, check that value against the one in the app's code. If there is a match, it means that no update is required, otherwise, "force" the user to update the app to the latest version by opening the app's page from Google Play.

Another solution might also be to use Android In-app updates:

When your users keep your app up to date on their devices, they can try new features, as well as benefit from performance improvements and bug fixes. Although some users enable background updates when their device is connected to an unmetered connection, other users might need to be reminded to install updates. In-app updates are a Play Core library feature that prompts active users to update your app.

So it's up to you to decide which one is better. Please note, that if you'll use the first one, you'll have to pay for a document read, each time a user opens the app.

Related