2016-02-17 168 views

回答

0

對於那些不知道的人,也花了一點時間弄清楚。 必須通過umzug的測試來了解發生了什麼。

設置儘可能接近sequelize-cli(不得不深入探索sequilize-cli),因此您不必更改遷移文件。

我正在使用TypeScript,我希望它不會是一個問題,以瞭解它是如何工作的。

import * as Sequelize from "sequelize"; 
import * as Umzug from "umzug"; 

let dbConfig = { 
    "dialect": "sqlite", 
    "storage": "test.db", 
    "seederStorage": "sequelize" 
}, 
let sequelize = new Sequelize(dbName, username, password, dbConfig); 

let umzug = new Umzug({ 
    storage: "sequelize", 
    storageOptions: { 
     sequelize: sequelize, 
     // tableName: "migrations" 
     tableName: "SequelizeData" // default table name for sequelize-cli `seeder` 
    }, 
    migrations: { 
     path: "built/migrations/seeder", 
     params: [sequelize.getQueryInterface(), sequelize.Sequelize] // arguments for `up` and `down` 
    } 
}); 

... 

umzug.up(); 
umzug.down(); 

... 

遷移文件:

module.exports = { 
    up: function (queryInterface: QueryInterface, sequelize: DataTypes) { 
     return queryInterface.bulkInsert("some_table", {}); 
    }, 
    down: function (queryInterface: QueryInterface, sequelize: DataTypes) { 
     return queryInterface.bulkDelete("some_table", {}); 
    } 
};