我正在尝试使用 umzug/sequelize 但我根本无法运行 down 方法。我正在关注本教程。我想基本上用 up 和 down 方法创建迁移文件。up 方法成功执行,但调用 down 根本不是所有 umzug.down() 方法。
"use strict";
const Promise = require("bluebird");
const sqlite3 = require("sqlite3");
const path = require('path');
module.exports = {
up: function() {
return new Promise(function(resolve, reject) {
/* up is to commit migrations to the database */
let db = new sqlite3.Database('./database/db.db');
db.run(`PRAGMA foreign_keys = ON`);
db.serialize(function() {
db.run(`CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT
)`);
});
db.close();
});
},
down: function() {
return new Promise(function(resolve, reject) {
/* roll back database changes made by this migration */
console.log('in down')
let db = new sqlite3.Database("./database/db.db");
db.serialize(function() {
db.run(`DROP TABLE users`);
});
db.close();
});
}
};
我的迁移文件也如下所示:
const path = require("path");
const Umzug = require("umzug");
let umzug = new Umzug({
logging: function() {
console.log.apply(null, arguments);
},
migrations: {
path: "./database/migrations",
pattern: /\.js$/
},
upName: "up",
downName: "down"
});
const cmd = process.argv[2].trim();
// this will run your migrations
if(cmd=='up')
{
umzug.up().then(console.log("Migrations committed"));
}
else if (cmd=='down'){
umzug.down().then(console.log("Migrations revereted"));
}
当我执行 node migrate.js up 时,它可以工作。但 down 永远不会被执行。我错过了什么吗?