Thursday, June 7th, 2007

GearShift: DB Migration Handling Library

Category: Gears, Google, JavaScript, Library

It is definitely feeling like Google Gears week. We are getting a lot of emails from people with little Gears projects.

With the ability to have a local store on clients accessing your web service, you also have the bane of having to deal with your clients having a certain version of that store.

One of the beauties of server-side development is that you are in charge of the data in one place (ignoring the complexities of slaves, multiple dbs etc). This means that when you upgrade your web application, you can change the db once on the server, and you have the new version for everyone. Mark Lucovsky wrote about this many years ago.

When we push functionality out to the client, we get added complexity to deal with, to go with new power. When a client talks to you, what version are they using? Have you upgraded the web application in a way that causes the client to require a local DB upgrade? As time goes on, this management gets more and more complicated.

Rails has fantastic support for managing DB changes through its ActiveRecord Migrations.

Patrick Quinn-Graham has ported some of the ideas to JavaScript with GearShift.


  1. // Setup your rules
  2. Gearshift.rules[1] = {
  3.     // create the demo table
  4.     up: function() {
  5.         return this.e("CREATE TABLE demo_table (
  6.                     id INTEGER PRIMARY KEY
  7.                     AUTOINCREMENT,
  8.                     name VARCHAR(30),
  9.                     movie VARCHAR(30)
  10.             )").success;
  11.     },
  12.     down: function() {
  13.         return this.e("DROP TABLE demo_table").success;
  14.     }
  15. };
  17. // Init the process
  18. // db = google.gears.factory.create('beta.database', '1.0');
  20. Gearshift.init(db, true);
  22. // Helper methods
  23. Gearshift.whatIsMyVersion()
  24. Gearshift.latestVersion() // highest rule possible
  25. Gearshift.migrateTo(version) // manually migrate

I am interested to see how projects manage the local stores. It isn’t like this is a new problem for us to deal with, but we need to be disciplined, as little tweaks and pushes to a live site can affect users in new ways.

Posted by Dion Almaer at 5:29 am

3.3 rating from 7 votes


Comments feed TrackBack URI

The link is broken, it should go to

Comment by sitharus — June 7, 2007

really nice project,i think we need a framework on top of Google Gears,as the api is very low level.

Comment by uriel katz — June 7, 2007

Leave a comment

You must be logged in to post a comment.