2014-09-01 17:18:45 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-04-24 10:10:34 -04:00
|
|
|
var assert = require('assert')
|
2014-05-28 22:29:34 -04:00
|
|
|
var testConfig = process.env.KNEX_TEST && require(process.env.KNEX_TEST) || {};
|
|
|
|
var _ = require('lodash');
|
|
|
|
var Promise = require('bluebird');
|
|
|
|
|
2014-08-11 12:25:39 +02:00
|
|
|
// excluding oracle and maria dialects from default integrations test
|
2015-05-01 11:26:29 -04:00
|
|
|
var testIntegrationDialects = (process.env.DB || "maria mysql mysql2 postgres sqlite3").match(/\w+/g);
|
2014-08-11 12:25:39 +02:00
|
|
|
|
2014-05-28 22:29:34 -04:00
|
|
|
var pool = {
|
|
|
|
afterCreate: function(connection, callback) {
|
2015-04-24 10:10:34 -04:00
|
|
|
assert.ok(typeof connection.__knexUid !== 'undefined')
|
2014-05-28 22:29:34 -04:00
|
|
|
callback(null, connection);
|
|
|
|
},
|
2014-08-28 20:34:09 +02:00
|
|
|
beforeDestroy: function(connection, continueFunc) {
|
2015-04-24 10:10:34 -04:00
|
|
|
assert.ok(typeof connection.__knexUid !== 'undefined')
|
2014-08-28 20:34:09 +02:00
|
|
|
continueFunc();
|
2014-05-28 22:29:34 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-30 21:19:33 -04:00
|
|
|
var mysqlPool = _.extend({}, pool, {
|
|
|
|
afterCreate: function(connection, callback) {
|
2016-03-15 21:14:17 +01:00
|
|
|
Promise.promisify(connection.query, {context: connection})("SET sql_mode='TRADITIONAL';", []).then(function() {
|
2015-04-30 21:19:33 -04:00
|
|
|
callback(null, connection);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var mariaPool = _.extend({}, pool, {
|
|
|
|
afterCreate: function(connection, callback) {
|
|
|
|
var query = connection.query("SET sql_mode='TRADITIONAL';", [])
|
|
|
|
query.on('result', function(result) {
|
|
|
|
result.on('end', function() {
|
|
|
|
callback(null, connection)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-05-28 22:29:34 -04:00
|
|
|
var migrations = {
|
2014-07-21 19:56:42 -04:00
|
|
|
directory: 'test/integration/migrate/migration'
|
2014-05-28 22:29:34 -04:00
|
|
|
};
|
|
|
|
|
2014-07-21 18:38:40 -04:00
|
|
|
var seeds = {
|
2014-07-21 19:56:42 -04:00
|
|
|
directory: 'test/integration/seed/seeds'
|
2014-07-21 18:38:40 -04:00
|
|
|
};
|
|
|
|
|
2014-08-11 12:25:39 +02:00
|
|
|
var testConfigs = {
|
2016-03-08 08:41:13 +01:00
|
|
|
|
2014-06-03 23:27:37 -04:00
|
|
|
maria: {
|
2014-07-09 10:36:40 -04:00
|
|
|
dialect: 'maria',
|
2014-06-03 23:27:37 -04:00
|
|
|
connection: testConfig.maria || {
|
|
|
|
db: "knex_test",
|
|
|
|
user: "root",
|
2015-04-30 21:19:33 -04:00
|
|
|
charset: 'utf8',
|
|
|
|
host: '127.0.0.1'
|
2014-06-03 23:27:37 -04:00
|
|
|
},
|
2015-04-30 21:19:33 -04:00
|
|
|
pool: mariaPool,
|
2014-07-21 18:38:40 -04:00
|
|
|
migrations: migrations,
|
|
|
|
seeds: seeds
|
2014-06-03 23:27:37 -04:00
|
|
|
},
|
|
|
|
|
2014-05-28 22:29:34 -04:00
|
|
|
mysql: {
|
2014-07-09 10:36:40 -04:00
|
|
|
dialect: 'mysql',
|
2014-05-28 22:29:34 -04:00
|
|
|
connection: testConfig.mysql || {
|
|
|
|
database: "knex_test",
|
2014-06-03 09:56:37 -04:00
|
|
|
user: "root",
|
|
|
|
charset: 'utf8'
|
2014-05-28 22:29:34 -04:00
|
|
|
},
|
2015-04-30 21:19:33 -04:00
|
|
|
pool: mysqlPool,
|
2014-07-21 18:38:40 -04:00
|
|
|
migrations: migrations,
|
|
|
|
seeds: seeds
|
2014-05-28 22:29:34 -04:00
|
|
|
},
|
|
|
|
|
2014-06-09 16:27:03 -04:00
|
|
|
mysql2: {
|
2014-07-09 10:36:40 -04:00
|
|
|
dialect: 'mysql2',
|
2014-06-09 16:27:03 -04:00
|
|
|
connection: testConfig.mysql || {
|
|
|
|
database: "knex_test",
|
|
|
|
user: "root",
|
|
|
|
charset: 'utf8'
|
|
|
|
},
|
2015-04-30 21:19:33 -04:00
|
|
|
pool: mysqlPool,
|
2014-07-21 18:38:40 -04:00
|
|
|
migrations: migrations,
|
|
|
|
seeds: seeds
|
2014-06-09 16:27:03 -04:00
|
|
|
},
|
|
|
|
|
2014-08-11 12:25:39 +02:00
|
|
|
oracle: {
|
2015-04-27 15:58:48 -04:00
|
|
|
client: 'strong-oracle',
|
2014-08-11 12:25:39 +02:00
|
|
|
connection: testConfig.oracle || {
|
|
|
|
adapter: "oracle",
|
|
|
|
database: "knex_test",
|
|
|
|
user: "oracle"
|
|
|
|
},
|
|
|
|
pool: pool,
|
|
|
|
migrations: migrations
|
|
|
|
},
|
2014-06-09 16:27:03 -04:00
|
|
|
|
2014-05-28 22:29:34 -04:00
|
|
|
postgres: {
|
2014-07-09 10:36:40 -04:00
|
|
|
dialect: 'postgres',
|
2014-05-28 22:29:34 -04:00
|
|
|
connection: testConfig.postgres || {
|
|
|
|
adapter: "postgresql",
|
|
|
|
database: "knex_test",
|
|
|
|
user: "postgres"
|
|
|
|
},
|
|
|
|
pool: pool,
|
2014-07-21 18:38:40 -04:00
|
|
|
migrations: migrations,
|
|
|
|
seeds: seeds
|
2014-05-28 22:29:34 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
sqlite3: {
|
2014-07-09 10:36:40 -04:00
|
|
|
dialect: 'sqlite3',
|
2015-12-08 11:37:31 -06:00
|
|
|
connection: testConfig.sqlite3 || {
|
2014-06-13 13:14:35 -04:00
|
|
|
filename: __dirname + '/test.sqlite3'
|
2014-05-28 22:29:34 -04:00
|
|
|
},
|
2015-04-27 15:58:48 -04:00
|
|
|
pool: pool,
|
2014-07-21 18:38:40 -04:00
|
|
|
migrations: migrations,
|
|
|
|
seeds: seeds
|
2015-12-08 11:37:31 -06:00
|
|
|
},
|
2016-03-08 08:41:13 +01:00
|
|
|
|
2015-12-14 11:10:46 -06:00
|
|
|
mssql: {
|
|
|
|
dialect: 'mssql',
|
|
|
|
connection: testConfig.mssql || {
|
|
|
|
user: "knex_test",
|
|
|
|
password: "knex_test",
|
2015-12-14 16:21:27 -06:00
|
|
|
server: "127.0.0.1",
|
2015-12-14 11:10:46 -06:00
|
|
|
database: "knex_test"
|
|
|
|
},
|
|
|
|
pool: pool,
|
|
|
|
migrations: migrations,
|
|
|
|
seeds: seeds
|
2015-03-24 17:48:14 -07:00
|
|
|
}
|
2014-08-11 12:25:39 +02:00
|
|
|
};
|
2014-05-28 22:29:34 -04:00
|
|
|
|
2014-08-11 12:25:39 +02:00
|
|
|
// export only copy the specified dialects
|
|
|
|
module.exports = _.reduce(testIntegrationDialects, function (res, dialectName) {
|
|
|
|
res[dialectName] = testConfigs[dialectName];
|
|
|
|
return res;
|
|
|
|
}, {});
|