umzug down方法未运行



我正在尝试使用 umzug/sequelize,但我根本无法运行 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"));
}

当我进行节点迁移时.js向上它可以工作。 但向下永远不会被执行。我错过了什么吗?

在某些时候,你需要在 Promise 上调用 resolve(( 或 reject(( 来执行 up 和 down 函数。

最新更新