不要怂,就是干,撸起袖子干!

Commit b9fbc3f8 by Mick Hansen

fix(connections): get db version via write replication config if defined, closes #4838

1 parent a649ee53
...@@ -212,7 +212,7 @@ ConnectionManager.prototype.getConnection = function(options) { ...@@ -212,7 +212,7 @@ ConnectionManager.prototype.getConnection = function(options) {
if (this.versionPromise) { if (this.versionPromise) {
promise = this.versionPromise; promise = this.versionPromise;
} else { } else {
promise = this.versionPromise = self.$connect(self.config).then(function (connection) { promise = this.versionPromise = self.$connect(self.config.replication.write || self.config).then(function (connection) {
var _options = {}; var _options = {};
_options.transaction = { connection: connection }; // Cheat .query to use our private connection _options.transaction = { connection: connection }; // Cheat .query to use our private connection
_options.logging = function () {}; _options.logging = function () {};
......
'use strict';
/* jshint -W030 */
/* jshint -W110 */
var chai = require('chai')
, Sequelize = require('../../index')
, expect = chai.expect
, Support = require(__dirname + '/support')
, DataTypes = require(__dirname + '/../../lib/data-types')
, dialect = Support.getTestDialect()
, sinon = require('sinon')
, _ = require('lodash')
, moment = require('moment')
, Promise = require('bluebird');
describe(Support.getTestDialectTeaser('Replication'), function() {
if (dialect === 'sqlite') return;
beforeEach(function () {
this.sequelize = Support.getSequelizeInstance(null, null, null, {
replication: {
// Just need empty objects, sequelize will copy in defaults
write: Support.getConnectionOptions(),
read: [Support.getConnectionOptions()]
}
});
expect(this.sequelize.connectionManager.pool.write).to.be.ok;
expect(this.sequelize.connectionManager.pool.read).to.be.ok;
this.User = this.sequelize.define('User', {
firstName: {
type: DataTypes.STRING,
field: 'first_name'
}
});
return this.User.sync({force: true});
});
it('should be able to make a write', function () {
return this.User.create({
firstName: Math.random().toString()
});
});
it('should be able to make a read', function () {
return this.User.findAll();
});
});
\ No newline at end of file
...@@ -110,6 +110,14 @@ var Support = { ...@@ -110,6 +110,14 @@ var Support = {
return this.getSequelizeInstance(config.database, config.username, config.password, sequelizeOptions); return this.getSequelizeInstance(config.database, config.username, config.password, sequelizeOptions);
}, },
getConnectionOptions: function(options) {
var config = Config[this.getTestDialect()];
delete config.pool;
return config;
},
getSequelizeInstance: function(db, user, pass, options) { getSequelizeInstance: function(db, user, pass, options) {
options = options || {}; options = options || {};
options.dialect = options.dialect || this.getTestDialect(); options.dialect = options.dialect || this.getTestDialect();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!