Skip to content

Commit

Permalink
second database line for parallel queries
Browse files Browse the repository at this point in the history
Signed-off-by: Tobias Gurtzick <magic@wizardtales.com>
  • Loading branch information
wzrdtales committed Sep 7, 2023
1 parent d564a48 commit 5bafb17
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions connect.js
Expand Up @@ -9,7 +9,9 @@ var path = require('path');
var log = require('db-migrate-shared').log;
const Promise = require('bluebird');

exports.connect = function (config, PassedClass) {
Promise.promisifyAll(driver);

exports.connect = async function (config, PassedClass) {
var internals = {};
var prefix = 'migration';
if (config.config) {
Expand All @@ -18,13 +20,23 @@ exports.connect = function (config, PassedClass) {
config = config.config;
}

const db2 = await driver.connectAsync(config, internals);

return Promise.fromCallback(callback => {
driver.connect(config, internals, function (err, db) {
if (err) {
callback(err);
return;
}

const realClose = db.close;
// close both lines with one disconnect action
db.close = function (cb) {
db2.close(function () {});
db.close = realClose;
db.close(cb);
};

var dirPath = path.resolve(
internals.argv['migrations-dir'] || 'migrations'
);
Expand Down Expand Up @@ -59,7 +71,8 @@ exports.connect = function (config, PassedClass) {
dirPath,
internals.mode !== 'static',
internals,
prefix
prefix,
{ db2 }
)
);
});
Expand Down Expand Up @@ -100,6 +113,7 @@ exports.connect = function (config, PassedClass) {
db,
oldClose,
prefix,
db2,
cb
);
};
Expand All @@ -115,7 +129,8 @@ exports.connect = function (config, PassedClass) {
dirPath,
internals.mode !== 'static',
internals,
prefix
prefix,
{ db2 }
)
);
}
Expand All @@ -142,6 +157,7 @@ function migrationFiles (
db,
close,
prefix,
db2,
cb
) {
var file;
Expand Down Expand Up @@ -187,7 +203,8 @@ function migrationFiles (
internals.argv['migrations-dir'],
internals.mode !== 'static',
internals,
prefix
prefix,
{ db2 }
)
);

Expand Down
2 changes: 1 addition & 1 deletion lib/walker.js
Expand Up @@ -24,7 +24,7 @@ const INTERFACES = {
'static-seed': require('./interface/seederInterface.js')
};

const Walker = function (driver, directory, mode, intern, prefix) {
const Walker = function (driver, directory, mode, intern, prefix, opts = {}) {
this.driver = dbmUtil.reduceToInterface(driver, INTERFACES[prefix]);
this._driver = driver;
Promise.promisifyAll(this._driver);
Expand Down

0 comments on commit 5bafb17

Please sign in to comment.