I actually thing a better approach would be using the version already
build into the Web Database like is described in this blog post:
http://blog.maxaller.name/2010/03/html5-web-sql-database-intro-to-versioning-and-migrations/
He created a github project which has a migrations script which might
be useful but I have also built this version control into a light
javascript library I wrote called html5sql (
https://github.com/
KenCorbettJr/html5sql). Using this javascript library you can easily
process all of the statements you need to set up your tables in
sequence all the while controlling the version of your database.
Basically, using html5sql you would open your database by calling
something like this:
html5sql.openDatabase("
com.yourDatabase.name", "Your Database",
200000);
You notice that unlike the native openDatabase function you do not
pass it a version parameter. This is because the script automatically
opens a new database with an empty version, or your existing database
with whatever version it happens to be.
You would then initially handle versioning by doing something like
this:
$.get("
http://www.yourserver.com/currentVersion.php",
function(serverVersion){
if(html5sql.database.version != serverVersion){
$.get("
http://www.yourserver.com/databaseSetupSQL.sql",
function(sql){
html5sql.changeVersion(html5sql.database.version,serverVersion,
sql,
function(){
//Success Callback after each and every SQL
//Statement has been processed in sequential
order
},
function(error, statement){
//An error callback if any of your statements
have
//an error. Encountering an error rolls back any
//any transactions that were completed before the
error.
}
);
}
);
}
}
);
I hope the code is clear but basically you would open the database,
query your server for the version of the database on the server, if it
didn't match you would retrieve a set of sql statements which would
drop and then rebuild the client's database based on the server's
instruction. The beauty of the html5sql javascript library is the sql
you retrieve would be processed in the sequence they were listed.
Hopefully this helps.
Ken Corbett