【问题标题】:How do you test that an Titanium Alloy migration will work?您如何测试钛合金迁移是否有效?
【发布时间】: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


【解决方案1】:

只要您的第一个迁移文件(您在创建模型时创建的那个)与此处的向下迁移匹配,您应该没问题。

像这样:

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();
};

此迁移文件的时间戳必须小于您在原始问题中列出的时间戳。

【讨论】:

    猜你喜欢
    • 2017-02-22
    • 2015-04-13
    • 1970-01-01
    • 1970-01-01
    • 2011-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多