After doing some research, it seems that when people ask about schema migration in CouchDB, they get quickly rebutted that the concept is not exactly compatible with NoSQL ideology. I understand how NoSQL is meant to be schema-less and it feels counter-intuitive. Nevertheless, I am in such a situation that I do not see how schema migration can be totally avoided. I use NoSQL with mobile devices. Here's the big lines of my set-up and my needs.
- Each mobile device has its own replicated database.
- The mobile device can work offline.
- Mobile devices replicates with a database on the cloud server to share their data.
- The data replicates when possible so multiple users on different devices can work on the same data.
- A newer version of the client could decide to change the value type it stores for a particular key (i.e. the equivalent of a schema change)
- The users might not update the app as soon as an update is available.
- A user that is not updated should be able to still work on the same data as the users who are updated.
Edit:
- The application is 100% native code.
My problem here is that a user with a client that is an old version of the software would not expect the new data to be a string instead of an int per se. Thus, handling it client-side can not always be done since we do not want to force the users to update their apps.
To explain it under another angle what happens is that I want two users with two different client versions to be able to share and modify the same data, meaning that I need to have backward and forward compatibility. Backward compatibility is often tackled, but forward compatibility is a bit more problematic. I need a way to continue to use my last-modified heuristic for conflict resolution while having a version that can not interpret the new schema fully.
After some thinking, I could consider an approach where I should split the cloud database into multiple sources; one where every mobile device pushes its modifications and one-to-x databases where the mobile devices pull the most recent data adapted to their versions. Somewhere in between those I should handle backward and forward compatibility with schema migrations.
Is there a way to avoid schema migrations, even in such a set-up? Do anyone see any other simpler or safer solutions? What are the limitations of such a system? I do not feel that I am exactly on the right track here.
Thanks, Paul