Wednesday, 15 February 2012

How do you test that an Titanium Alloy migration will work? -



How do you test that an Titanium Alloy migration will work? -

i'm release app update of iphone app i've written in titanium alloy. i've added new column database, i've written migration it. upwards migration simple enough, altering table add together new column. however, downwards migration has little worried involved creating temporary database, storing info need, , dropping existing info base of operations , creating new 1 stored data, in order maintain remove column.

how test code right , work?

here migrations:

migration.up = function(migrator) { migrator.db.execute('alter table ' + migrator.table + ' add together column is_sample boolean;'); }; migration.down = function(migrator) { var db = migrator.db; var table = migrator.table; db.execute('create temporary table beers_backup(alloy_id,name,brewery,rating,percent,establishment,location,notes,date,date_string,beer_image,latitude,longitude,favourite);'); db.execute('insert beers_backup select alloy_id,name,brewery,rating,percent,establishment,location,notes,date,date_string,beer_image,latitude,longitude,favourite ' + table + ';'); migrator.droptable(); migrator.createtable({ columns: { "name": "text", "brewery": "text", "rating": "integer", "percent": "integer", "establishment": "text", "location": "text", "notes": "text", "date": "text", "date_string": "text", "beer_image": "text", "latitude": "integer", "longitude": "integer", "favourite": "boolean" }, }); db.execute('insert ' + table + ' select alloy_id,name,brewery,rating,percent,establishment,location,notes,date,date_string,beer_image,latitude,longitude,favourite beers_backup;'); db.execute('drop table beers_backup;'); };

you should fine long first migration file (the 1 created when created model) matches downward migration here.

like this:

migration.up = function(migrator){ migrator.createtable({ columns: { "name": "text", "brewery": "text", "rating": "integer", "percent": "integer", "establishment": "text", "location": "text", "notes": "text", "date": "text", "date_string": "text", "beer_image": "text", "latitude": "integer", "longitude": "integer", "favourite": "boolean" } }); }; migration.down = function(migrator) { migrator.dropttable(); };

this migration file has have timestamp less 1 listed in original question.

titanium titanium-mobile appcelerator titanium-alloy

No comments:

Post a Comment