【发布时间】:2014-06-26 19:50:09
【问题描述】:
我即将发布我用钛合金编写的 iPhone 应用程序的应用程序更新。我在数据库中添加了一个新列,所以我为它编写了一个迁移。向上迁移很简单,只需更改表以添加新列。但是,向下迁移有点担心,因为它涉及创建一个临时数据库,存储我需要的数据,然后删除现有数据库并使用存储的数据创建一个新数据库,以保持删除列。
我如何测试这段代码是否正确并且可以工作?
这是我的迁移:
migration.up = function(migrator) {
migrator.db.execute('ALTER TABLE ' + migrator.table + ' ADD 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 INTO beers_backup SELECT alloy_id,name,brewery,rating,percent,establishment,location,notes,date,date_string,beer_image,latitude,longitude,favourite FROM ' + 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 INTO ' + table + ' SELECT alloy_id,name,brewery,rating,percent,establishment,location,notes,date,date_string,beer_image,latitude,longitude,favourite FROM beers_backup;');
db.execute('DROP TABLE beers_backup;');
};
【问题讨论】:
-
我猜你没有以前的应用程序版本可用?
-
很遗憾没有,但如果我需要这样做,我可以使用版本控制回滚应用程序并创建构建?
标签: titanium titanium-mobile appcelerator titanium-alloy