richard
richard

Reputation: 3309

How do implement schema changes in a NOSQL storage system

How do you manage a major schema change when you are using a Nosql store like SimpleDB?

I know that I am still thinking in SQL terms, but after working with SimpleDB for a few weeks I need to make a change to a running database. I would like to change one of the object classes to have a unique id, as rather than a business name, and as it is referenced by another object, I will need to also update the reference value in these objects.

With a SQL database you would run set of sql statements as part of the client software deployment process. Obviously this will not work with something like SimpleDB as

Some solutions I have thought of are

It all is rather complex and I am wondering if I am missing something?

Thanks

Richard

Upvotes: 9

Views: 3192

Answers (2)

Tom Clarkson
Tom Clarkson

Reputation: 16174

I use something similar to your second option, but without the version attribute.

First, try to keep your changes to things that are easy to make backward compatible - changing the primary key is the worst case scenario for this.

Removing a field is easy - just stop writing to that field once all servers are running a version that doesn't require it.

Adding a field requires that you never write that object using code that won't save that field. If you can't deploy the new version everywhere at once, use an intermediate version that supports saving the field before you deploy a version that requires it.

Changing a field is just a combination of these two operations.

With this approach changes are applied as needed - write using the new version, but allow reading of the old version with default or derived values for the new field.

You can use the same code to update all records at once, though this may not be appropriate on a large dataset.

Changing the primary key can be handled the same way, but could get really complex depending on which nosql system you are using. You are probably stuck with designing custom migration code in this case.

Upvotes: 5

Justin King
Justin King

Reputation: 1428

RavenDB another NoSQL database uses migrations to acheive this

http://ayende.com/blog/66563/ravendb-migrations-rolling-updates

http://ayende.com/blog/66562/ravendb-migrations-when-to-execute

Normally these type of changes are handled by your application that changes the schema to a newer one upon loading version X and converting to version Y and persisting

Upvotes: 1

Related Questions