From 6e673a96fc1de9bc1a39fa8e11d8e48d5e34de25 Mon Sep 17 00:00:00 2001 From: wkkwok Date: Thu, 18 Feb 2016 17:59:47 +0800 Subject: [PATCH 1/4] Change: Change the arguments of syncDiff. Change the arguments of syncDiff to same as Sequelize constructor. Using url affects compatibility as older versions of postgresql does not support. Also, sometimes is troublesome when database user password contain special characters, e.g. '@', '/'... --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 40a3cd3..2d4f19e 100644 --- a/index.js +++ b/index.js @@ -27,9 +27,9 @@ module.exports = function(Sequelize) { } }) - Sequelize.prototype.syncDiff = function(url, options) { + Sequelize.prototype.syncDiff = function(database, username, password, options) { var self = this - var sequelize = new Sequelize(url, options || this.options) + var sequelize = new Sequelize(database, username, password, options || this.options) this.diff_actions.forEach(function(action) { if (!action.model) { sequelize[action.method].apply(sequelize, action.args) From 86124d4416de4aee8f10a99579d0c341c7912bc2 Mon Sep 17 00:00:00 2001 From: wkkwok Date: Thu, 18 Feb 2016 18:44:19 +0800 Subject: [PATCH 2/4] Change: Cont. Change the arguments of syncDiff. Pass config objects instead of urls to dbdiff. --- index.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 2d4f19e..a4a6afc 100644 --- a/index.js +++ b/index.js @@ -49,21 +49,24 @@ module.exports = function(Sequelize) { dbdiff.logger = function(msg) { arr.push(msg) } - var selfURL = self.config.protocol+'://' - if (self.config.username && self.config.password) { - selfURL += self.config.username+':'+self.config.password+'@' - } - selfURL += self.config.host - if (self.config.port) { - selfURL += ':'+self.config.port - } - selfURL += '/'+self.config.database - if (self.options.dialectOptions && self.options.dialectOptions.ssl) { - selfURL += '?ssl=true' - } - + var masterConfig = { + host: self.config.host, + port: self.config.port, + user: self.config.username, + password: self.config.password, + database: self.config.database, + ssl: self.config.ssl + }; + var dummyConfig = { + host: options.host, + port: options.port, + user: username, + password: password, + database: database, + ssl: options.ssl + }; return new Promise(function (resolve, reject) { - dbdiff.compareDatabases(selfURL, url, function(err) { + dbdiff.compareDatabases(masterConfig, dummyConfig, function(err) { err ? reject(err) : resolve(arr.join('\n')) }) }) From d4bb2ca506ffe630e07de8b34d23808526f89360 Mon Sep 17 00:00:00 2001 From: wkkwok Date: Thu, 18 Feb 2016 22:59:42 +0800 Subject: [PATCH 3/4] Change: Do not sync master --- index.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/index.js b/index.js index a4a6afc..2c4cd4f 100644 --- a/index.js +++ b/index.js @@ -40,10 +40,7 @@ module.exports = function(Sequelize) { } }) - return self.sync() - .then(function() { - return sequelize.sync({ force: true }) - }) + return sequelize.sync({ force: true }) .then(function() { var arr = [] dbdiff.logger = function(msg) { From 47660104b4a0efe0d14fc3573f8a3032640ec321 Mon Sep 17 00:00:00 2001 From: wkkwok Date: Sat, 20 Feb 2016 12:42:20 +0800 Subject: [PATCH 4/4] Change: Support URLs also I checked Sequelize constructor source code. I found that it can handle the conversion between URLs and connection config object. Therefore, just get config object from sequelize instance instead of passing-in argument should do the job. --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 2c4cd4f..4e2c390 100644 --- a/index.js +++ b/index.js @@ -55,12 +55,12 @@ module.exports = function(Sequelize) { ssl: self.config.ssl }; var dummyConfig = { - host: options.host, - port: options.port, - user: username, - password: password, - database: database, - ssl: options.ssl + host: sequelize.config.host, + port: sequelize.config.port, + user: sequelize.config.username, + password: sequelize.config.password, + database: sequelize.config.database, + ssl: sequelize.config.ssl }; return new Promise(function (resolve, reject) { dbdiff.compareDatabases(masterConfig, dummyConfig, function(err) {