umzug down method not running

1.1k Views Asked by At

I am trying to use umzug/sequelize but I can't run the down method at all. I am following this tutorial. I want to basically create migration files with up and down methods. The up method gets executed successfully but calling down does not all the umzug.down() method at all.

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

My migrate file looks like this as well:

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

When I do node migrate.js up it works. but down never gets executed. Am I missing something?

1

There are 1 best solutions below

0
On

At some point, you will need to call the resolve() or reject() on the Promise for both your up and down functions.