I am working on an app that will be cross-platform: web, android, iOS. I have a couple objects that are intended to specify some constants, like valid states. For example:
No, Firebase has no built-in versioning.
Not at all. This is a common problem with any database schema upgrade in a client-server context that I've ever seen. Catering for multiple versions of clients while upgrading your database schema is not simple, no matter which database you use.
There are a few common ways of handling this:
What you've done is the most common way of solving this: create a secondary data structure that has the new structure. If the structure is writeable, that means you'll have to reconcile writes to update both locations. And since you can't update the old app, you'll have to do part of this with a non-client script. Yup, it's painful.
One alternative you sometimes see is a forced upgrade, which means that you keep a top-level current-schema-version
in your database and the client checks whether is can read/write that version. If not, it simply aborts.
Given that this is read-only (probably administrative) data, I'd recommend setting up an admin dashboard for your application. When you add a new state
in that dashboard, it can write it to both places.
Assuming you have an old app v1.0 and a new one v2.0, you have 50 clients reading/writing as per v1.0 and 50 clients reading/writing as per v2.0.
The only question is if those groups of clients interact with each other or not?
If no, they are happy with their app.
If yes, v2.0 clients have to read data from v1.0 fields and upgrade it to v2.0 fields (default or with additional data from v2.0 clients) and while writing write v1.0 fields and then write additional v2.0 fields.
The theory applies to one client interacting with multiple other version clients.
Since firebase is schemaless, you can have two nodes of same category containing different number of fields, without problem. Hence with firebase, you should only take care that you won’t change the meaning of a field between the versions. In the newer versions, always keep the old read/writes as it is and for the new data always create new fields.
Minimum required fields for a version to function must always be present in all higher versions of your product.