Coding Thoughts

  • Archive
  • RSS

Something to watch for with DatabaseSchemaUpdater

Local databases on Windows Phone 7.5 are a wonderful thing. They allow you to write beautiful code that takes full advantage of LINQ, and who doesn’t like LINQ right?!? (answer: crazy people). But, using databases doesn’t come without it’s headaches, and a common one is how you update it. 

Fortunately several clever people have already come up with a way of updating your database schema that involve using the DatabaseSchemaUpdater. In a nutshell that process involves something like this:

if (dbSchemaUpdater.DatabaseSchemaVersion < 1) {
     dbSchemaUpdater.AddColumn<MyTable1>(“NewColumn1”)
}
if (dbSchemaUpdater.DatabaseSchemaVersion < 2) { 
     dbSchemaUpdater.AddColumn<MyTable1>(“NewColumn2”)
}

dbSchemaUpdater.DatabaseSchemaVersion = 2;
dbSchemaUpdater.Execute();  

This works really well for most circumstances. However, there is a circumstance where by you can trip up as a developer. Consider that we release our app and it has a DatabaseSchemaVersion of 2. It’s great, everyone loves it, so we start work on an update with extra awesome in it. We need a new table so we add the following:

if (dbSchemaUpdater.DatabaseSchemaVersion < 3) {
     dbSchemaUpdater.AddTable<NewFeaturesTable>();
}

dbSchemaUpdater.DatabaseSchemaVersion = 3;
dbSchemaUpdater.Execute(); 

We run the app, it works. We’re in business, and off we start coding! Now all of a sudden we want to add a new column on that table so we revisit our database updating code and we add the following:

if (dbSchemaUpdater.DatabaseSchemaVersion < 4) {
     dbSchemaUpdater.AddColumn<NewFeaturesTable>(“MoreStuff”);
}

dbSchemaUpdater.DatabaseSchemaVersion = 4;
dbSchemaUpdater.Execute();  

We run it again on our test environment, GREAT! Still working. We even delete our app and reinstall it, still working. This is awesome! So we code our features up and we release it to the marketplace…. BUT it’s crashing for the user!!! WHY DOES IT CRASH! Well, this stumped me for a while, but lets take a look at what the code above is doing.

First of all, the user is coming in at schema version 2. Then, the db updater executes the following code:

1. It adds a NewFeaturesTable
2. It adds the column MoreStuff to the NewFeaturesTable

But that’s what we wanted wasn’t it? I mean, it worked fine in development so why isn’t it working now? Well, not quite… When we added the NewFeaturesTable to our schema originally it didnt have the MoreStuff column, so it didn’t exist, and therefore adding the column was fine.

However now, when the code executes on the user’s device, the NewFeaturesTable table that gets created will already have the MoreStuff column on it, and therefore when your code tries to add the column again, it will fail!

If anyone remembers the disaster that was Mehdoh 1.5 upgrade, then that was the cause. It’s REALLY easy to get carried away with just updating the DB Schema. You might add a new table, add another, update a few other tables, and then add another column to your first new table - it’s easily done.

You should always keep track of what the user will have and test their upgrade scenarios (not just yours!). Honestly, I can’t recommend enough that you do the following to help you avoid the above:

1. Keep copies of the XAP files you submit to the App Store.
2. Before you release any updates, install the previously submitted XAP onto your device and test your upgrade process.  
3. If you’ve got time, test a few other versions too! 

Hopefully someone can learn from my mistake here.

    • #windows phone
    • #wp7
    • #wp7dev
    • #mehdoh
    • #DatabaseSchemaUpdater
  • 1 year ago
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Mehdoh Certification update

Well, that was quick… Mehdoh has moved through the certification process and … Failed.

When you submit an application to the App Hub you have to enter a few details, description, version number etc… and also choose the price and availability of the app. The availability being what countries are allowed to download the app. I had selected all of them. As it happens Microsoft have added a few more countries recently and these countries don’t like the sort of content that Twitter apps potentially expose to their citizens. 

The countries that Microsoft highlighted were China, Malaysia, and Indonesia. So, I have resubmitted the app but without availability in those countries. Sorry about that, but those are the rules. Let’s see how it goes this time :)

    • #mehdoh
    • #twitter
    • #windows phone
    • #app hub
    • #wp7dev
  • 1 year ago
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

An update on Mehdoh

Back in December, due to various frustrations with the platform, I took the decision to close my App Hub (developer) account with Microsoft. It turned out that wasn’t such a smart idea! At the time I had NO IDEA that the upshot of that would be that the application would no longer be available to customers who had paid for it. I immediately sent several emails to various people and departments at Microsoft (yes, including Brandon Watson) asking for clarification and unfortunately they all eventually gave the same answer - that the account was gone, it couldn’t be recovered, and as such the application would no longer be available to re-download.

This, honestly, wasn’t acceptable to me, so I was left with a choice to make… Although thanks to a lot of very helpful people… I had several choices

1- I could hand the source code, and development, over to someone else (thank you to people who kindly offered!)

2- Someone else could host the application in their App Hub account (again thank you for those that offered to do this also!)

3- Microsoft’s suggestion, pay for a new account and re-upload it for certification again.

4- Or… forget about it…

I really did spend a lot of time contemplating choices 1 and 2… but ultimately I’d still like to retain control of the source code (it is, after all, a company asset rather than some kind of toy project) so that left 3 or 4… Well… 4 wasn’t really an option, so I have just taken Microsoft’s advice and signed up again.

OK so what does this mean? Well, it means that Mehdoh will continue to be on the store… however, as I understand it, it will NOT be the same application. ie. no reviews/downloads will carry across… and existing users WILL NOT automatically update to this new version - unfortunately even paid customers. Of course, I do not expect anyone to pay any more for the application than they may have already done, so with that in mind the application will be FREE. If you have paid for the previous version then you can rest safe in the knowledge that your investment went towards paying for the new application subscription, so thank you.

So what next? Well, if you want to carry on using the “new” Mehdoh, then you will need to download it (for FREE) as, as mentioned, under Microsoft’s rules it’s a different application. Note that as of this blog post the application is still under certification… but I will announce (via @mehdoh and www.mehdoh.com) when it’s available.

With regards to development… It will restart, albeit at a much slower pace. Previously I was putting in anything in the region of 5 or 6 hours a night, after doing a day’s work and taking care of family stuff. However going forward it will be on an as/when I can basis. The exciting part is that as I no longer own any of Windows Phones (I was using an LG Optimus 7 and a Nokia Lumia 800 for development and personal use, both were sold off) I will almost certainly be making use of the beta marketplace, something that I never did previously.

OK so what will be developed? At present I honestly don’t know… Some other bits have started, and are nearly there, but I will LIST them soon enough. I will also try and keep on top of any bug fixes (yes the submitted version has the fix for settings!). There are a few other bits that have been planned from day one, that I would still like to see in the app, but I can’t emphasise strongly enough that development will be a lot slower/sporadic than previously, so please don’t expect new releases every few weeks. Please remember that the account was taken out again primarily so that the app can stay on the store.

Anyway, Mehdoh is back, kind of!

    • #mehdoh
    • #windows phone
    • #microsoft
    • #app hub
    • #wpdev
    • #twitter
  • 1 year ago
  • 2
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

About

Christopher Field
England

Software Developer

Gamer

Twitter: @mrcfield
  • RSS
  • Random
  • Archive
  • Mobile
Effector Theme by Pixel Union