Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create custom migration with mysql pool #12

Open
nikolay-hristov opened this issue May 30, 2019 · 5 comments
Open

Cannot create custom migration with mysql pool #12

nikolay-hristov opened this issue May 30, 2019 · 5 comments

Comments

@nikolay-hristov
Copy link

nikolay-hristov commented May 30, 2019

I'm getting an error that conn.query is not a function.

This is my migration init:

let pool = mysql.createPool({
    connectionLimit : config.MYSQL_CONN_POOL,
    host     : config.MYSQL_HOST,
    user     : config.MYSQL_USER,
    password : config.MYSQL_PASSWORD,
    database : config.MYSQL_DATABASE
  });
migration.init(pool, __dirname + '/migrations');

This is my migration code:

module.exports = {
  'up' :  function (conn, cb) {
    conn.query (`ALTER TABLE progress DROP FOREIGN KEY progress_player_id;
    ALTER TABLE progress 
      ADD CONSTRAINT progress_player_id
        FOREIGN KEY (player_id)
        REFERENCES player (id)
        ON DELETE CASCADE
        ON UPDATE CASCADE;`, function (err, res) {
          cb();
    });
  },
  'down' : function (conn, cb) {
    conn.query (`ALTER TABLE progress DROP FOREIGN KEY progress_player_id;ALTER TABLE progress 
    ADD CONSTRAINT progress_player_id
      FOREIGN KEY (player_id)
      REFERENCES player (id)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION;`, function (err, res) {
          cb();
    });
  }
}
@rozhnev
Copy link

rozhnev commented May 30, 2019

Hi,
You must add requirements before pool init:
`
const mysql = require('mysql');
const migration = require('mysql-migrations');

let pool = mysql.createPool({
connectionLimit : config.MYSQL_CONN_POOL,
host : config.MYSQL_HOST,
user : config.MYSQL_USER,
password : config.MYSQL_PASSWORD,
database : config.MYSQL_DATABASE
});
migration.init(pool, __dirname + '/migrations');
`

@nikolay-hristov
Copy link
Author

nikolay-hristov commented Jun 5, 2019

Hi @rozhnev,

of course, I just didn't post them here, these are my requires

const pool = require('./storage/adapters/mysql_pool.js');
const config = require('./config.js');
const migration = require('mysql-migrations');

Note: My pool comes from another file, I concatenated the two for this issue

@nikolay-hristov
Copy link
Author

P.S. Normal migrations work, but custom ones return the error mentioned in the beginning

@okzapradhana
Copy link

I'm getting an error that conn.query is not a function.

This is my migration init:

let pool = mysql.createPool({
    connectionLimit : config.MYSQL_CONN_POOL,
    host     : config.MYSQL_HOST,
    user     : config.MYSQL_USER,
    password : config.MYSQL_PASSWORD,
    database : config.MYSQL_DATABASE
  });
migration.init(pool, __dirname + '/migrations');

This is my migration code:

module.exports = {
  'up' :  function (conn, cb) {
    conn.query (`ALTER TABLE progress DROP FOREIGN KEY progress_player_id;
    ALTER TABLE progress 
      ADD CONSTRAINT progress_player_id
        FOREIGN KEY (player_id)
        REFERENCES player (id)
        ON DELETE CASCADE
        ON UPDATE CASCADE;`, function (err, res) {
          cb();
    });
  },
  'down' : function (conn, cb) {
    conn.query (`ALTER TABLE progress DROP FOREIGN KEY progress_player_id;ALTER TABLE progress 
    ADD CONSTRAINT progress_player_id
      FOREIGN KEY (player_id)
      REFERENCES player (id)
      ON DELETE NO ACTION
      ON UPDATE NO ACTION;`, function (err, res) {
          cb();
    });
  }
}

I also faced this issue when using custom migration with function conn.query() is not a function , any workaround for this one?

@abubakarakram167
Copy link

Any luck with this issue @nikolay-hristov @rozhnev I am also facing this issue too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants