db-migrate / pg

A postgresql driver for db-migrate.
Other
67 stars 51 forks source link

Migration hangs on after Done if it includes `select` queries. #41

Closed skarm61 closed 5 years ago

skarm61 commented 5 years ago

db-migrate 0.11.5 db-migrate-pg 0.5.0 knex 0.16.5 express 4.16.4

When run migration like

const knex = require('../config/knex');

'use strict';

var dbm;
var type;
var seed;

/**
  * We receive the dbmigrate dependency from dbmigrate initially.
  * This enables us to not have to rely on NODE_PATH.
  */
exports.setup = function(options, seedLink) {
  dbm = options.dbmigrate;
  type = dbm.dataType;
  seed = seedLink;
};

exports.up = async (db) => {
  const offers = await knex.select().from('offers');
  console.log(offers);
};

exports.down = async (db) => {
  // ...
};

exports._meta = {
  "version": 1
};

Get in console:

$ - npm run db-migrate up

> project@1.0.0 db-migrate /Users/asapozhnikov/Projects/darly/soosty-be
> db-migrate --config config/database.json "up"

[INFO] Processed migration 20190416095203-some migration name
[INFO] Done

and it hangs on. All code inside migration executes well and does what it should. It hangs on even if there any other migrations after this one.

I have second migration, which works well if I run it without first one(which doesn't work well), but when I run both migrations - they do all what they should do, but in the end it hangs on after Done.

wzrdtales commented 5 years ago

Since you]re using knex here, look at this component. There is most probably some open event listeners created by knex, so this is not a db-migrate issue. Try removing and work with db.runSql instead and it most probably starts working.

wzrdtales commented 5 years ago

Feel free to reply shouldn't removing knex solve it, then I will reopen this, but for now I am pretty sure knex is the problem, try removing it once and then figure out how you can close the knex connections.