Example for database upgrade

Feb 12, 2011 at 10:59 PM

First congrats for your release, I use Sterling in my app for Windows Phone 7 and it works perfectly! (http://wp7wonders.wordpress.com/stacks-for-instapaper/)

I searched to see the example about the upgrade of existing database: http://sterling.codeplex.com/discussions/239428 but the link is not working anymore ?

If I add a new Property in one of my class,  I need to upgrade my database ? I tought thet a new Property would not be a problem (the value for existing objects would be null or the default one) ?

Matthieu

Coordinator
Feb 12, 2011 at 11:16 PM

Currently that's not the case because Sterling doesn't save a "table" but relies on the active type definition. Eventually that will be the route to go but unfortunately it's not yet available. Currently, Sterling has an algorithm to inspect properties and fields on the type, and then parses the stream based on those properties and fields. If you add a new property, it will expect additional data that doesn't exist.

Obviously the fix will be to serialize the list of properties in the table information and parse based on that, but then there are additional nuances such as when properties drop off or require defaults, etc, so it hasn't been addressed yet.

I'll try to figure out why the link is broken, but in essence the reference does this:

MyApplication
MyApplication.Models.MyClass
MyApplication.Database.MyDatabase

Then if I need to revise it, I'll do:

MyApplication.ModelsV2.MyClass, and
MyApplication.DatabaseV2.MyDatabase

Class name can stay the same, etc, and then I just detect if I've upgraded yet. If not, I have a special class that works in both namespaces, reads from the old and writes to the new. 

Probably eventually will be able to take something that simply inspects the stream and rebuilds the types as well - I've been toying with the idea of an out of browser "inspector" for Sterling like a SQL console but just haven't had bandwidth yet to delve into it.

I know upgrade is not a good story now, but will be focusing on some good solutions for it down the road.

Feb 16, 2011 at 9:56 PM

Thanks Jeremy for the answer. Yes upgrade path is not an easy task. If you find the sample project it would be helpful.

Matthieu

Jun 11, 2011 at 7:40 AM

I've posted a prototype solution for upgrading

have a look

 

http://sterling.codeplex.com/discussions/260876?ProjectName=sterling