2014-09-01 17:18:45 +02:00
|
|
|
'use strict';
|
2018-04-04 18:43:39 -04:00
|
|
|
/* eslint no-var: 0 */
|
2014-09-01 17:18:45 +02:00
|
|
|
|
2019-06-08 02:34:41 +02:00
|
|
|
const assert = require('assert');
|
2019-10-15 10:11:59 +03:00
|
|
|
const { promisify } = require('util');
|
2019-06-08 02:34:41 +02:00
|
|
|
const testConfig =
|
2018-07-09 08:10:34 -04:00
|
|
|
(process.env.KNEX_TEST && require(process.env.KNEX_TEST)) || {};
|
2019-06-08 02:34:41 +02:00
|
|
|
const _ = require('lodash');
|
2014-05-28 22:29:34 -04:00
|
|
|
|
2018-02-03 08:33:02 -05:00
|
|
|
// excluding redshift, oracle, and mssql dialects from default integrations test
|
2019-06-08 02:34:41 +02:00
|
|
|
const testIntegrationDialects = (
|
2021-10-02 23:45:17 +03:00
|
|
|
process.env.DB ||
|
|
|
|
'sqlite3 postgres pgnative mysql mysql2 mssql oracledb cockroachdb'
|
2018-07-09 08:10:34 -04:00
|
|
|
).match(/\w+/g);
|
2014-08-11 12:25:39 +02:00
|
|
|
|
2020-12-25 20:33:06 +02:00
|
|
|
console.log(`ENV DB: ${process.env.DB}`);
|
|
|
|
|
2019-06-08 02:34:41 +02:00
|
|
|
const pool = {
|
2020-04-19 00:40:23 +02:00
|
|
|
afterCreate: function (connection, callback) {
|
2018-07-09 08:10:34 -04:00
|
|
|
assert.ok(typeof connection.__knexUid !== 'undefined');
|
2014-05-28 22:29:34 -04:00
|
|
|
callback(null, connection);
|
2018-07-09 08:10:34 -04:00
|
|
|
},
|
2014-05-28 22:29:34 -04:00
|
|
|
};
|
|
|
|
|
2019-06-08 02:34:41 +02:00
|
|
|
const poolSqlite = {
|
2019-05-26 18:03:07 -07:00
|
|
|
min: 0,
|
|
|
|
max: 1,
|
2019-05-27 23:21:21 +02:00
|
|
|
acquireTimeoutMillis: 1000,
|
2020-04-19 00:40:23 +02:00
|
|
|
afterCreate: function (connection, callback) {
|
2019-05-26 18:03:07 -07:00
|
|
|
assert.ok(typeof connection.__knexUid !== 'undefined');
|
2020-12-08 07:49:41 -05:00
|
|
|
connection.run('PRAGMA foreign_keys = ON', callback);
|
2019-05-26 18:03:07 -07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-06-08 02:34:41 +02:00
|
|
|
const mysqlPool = _.extend({}, pool, {
|
2020-04-19 00:40:23 +02:00
|
|
|
afterCreate: function (connection, callback) {
|
2019-10-15 10:11:59 +03:00
|
|
|
promisify(connection.query)
|
|
|
|
.call(connection, "SET sql_mode='TRADITIONAL';", [])
|
2020-04-19 00:40:23 +02:00
|
|
|
.then(function () {
|
2019-10-15 10:11:59 +03:00
|
|
|
callback(null, connection);
|
|
|
|
});
|
2018-07-09 08:10:34 -04:00
|
|
|
},
|
2015-04-30 21:19:33 -04:00
|
|
|
});
|
|
|
|
|
2019-06-08 02:34:41 +02:00
|
|
|
const migrations = {
|
2018-07-09 08:10:34 -04:00
|
|
|
directory: 'test/integration/migrate/migration',
|
2014-05-28 22:29:34 -04:00
|
|
|
};
|
|
|
|
|
2019-06-08 02:34:41 +02:00
|
|
|
const seeds = {
|
2018-07-09 08:10:34 -04:00
|
|
|
directory: 'test/integration/seed/seeds',
|
2014-07-21 18:38:40 -04:00
|
|
|
};
|
|
|
|
|
2019-06-08 02:34:41 +02:00
|
|
|
const testConfigs = {
|
2014-05-28 22:29:34 -04:00
|
|
|
mysql: {
|
2018-07-08 14:10:51 +03:00
|
|
|
client: 'mysql',
|
2014-05-28 22:29:34 -04:00
|
|
|
connection: testConfig.mysql || {
|
2019-05-13 12:21:36 +03:00
|
|
|
port: 23306,
|
2018-07-09 08:10:34 -04:00
|
|
|
database: 'knex_test',
|
2019-05-13 12:21:36 +03:00
|
|
|
host: 'localhost',
|
|
|
|
user: 'testuser',
|
|
|
|
password: 'testpassword',
|
2018-07-09 08:10:34 -04:00
|
|
|
charset: 'utf8',
|
2014-05-28 22:29:34 -04:00
|
|
|
},
|
2015-04-30 21:19:33 -04:00
|
|
|
pool: mysqlPool,
|
2019-05-26 18:03:07 -07:00
|
|
|
migrations,
|
|
|
|
seeds,
|
2014-05-28 22:29:34 -04:00
|
|
|
},
|
|
|
|
|
2014-06-09 16:27:03 -04:00
|
|
|
mysql2: {
|
2018-07-08 14:10:51 +03:00
|
|
|
client: 'mysql2',
|
2014-06-09 16:27:03 -04:00
|
|
|
connection: testConfig.mysql || {
|
2019-05-13 12:21:36 +03:00
|
|
|
port: 23306,
|
2018-07-09 08:10:34 -04:00
|
|
|
database: 'knex_test',
|
2019-05-13 12:21:36 +03:00
|
|
|
host: 'localhost',
|
|
|
|
user: 'testuser',
|
|
|
|
password: 'testpassword',
|
2018-07-09 08:10:34 -04:00
|
|
|
charset: 'utf8',
|
2014-06-09 16:27:03 -04:00
|
|
|
},
|
2015-04-30 21:19:33 -04:00
|
|
|
pool: mysqlPool,
|
2019-05-26 18:03:07 -07:00
|
|
|
migrations,
|
|
|
|
seeds,
|
2014-06-09 16:27:03 -04:00
|
|
|
},
|
|
|
|
|
2016-10-14 17:00:39 +02:00
|
|
|
oracledb: {
|
|
|
|
client: 'oracledb',
|
|
|
|
connection: testConfig.oracledb || {
|
2019-05-13 12:21:36 +03:00
|
|
|
user: 'system',
|
|
|
|
password: 'Oracle18',
|
|
|
|
connectString: 'localhost:21521/XE',
|
2016-10-14 17:00:39 +02:00
|
|
|
// https://github.com/oracle/node-oracledb/issues/525
|
2018-07-09 08:10:34 -04:00
|
|
|
stmtCacheSize: 0,
|
2016-10-14 17:00:39 +02:00
|
|
|
},
|
2019-05-26 18:03:07 -07:00
|
|
|
pool,
|
|
|
|
migrations,
|
2016-10-14 17:00:39 +02:00
|
|
|
},
|
|
|
|
|
2014-05-28 22:29:34 -04:00
|
|
|
postgres: {
|
2018-07-08 14:10:51 +03:00
|
|
|
client: 'postgres',
|
2014-05-28 22:29:34 -04:00
|
|
|
connection: testConfig.postgres || {
|
2018-07-09 08:10:34 -04:00
|
|
|
adapter: 'postgresql',
|
2019-05-13 12:21:36 +03:00
|
|
|
port: 25432,
|
|
|
|
host: 'localhost',
|
2018-07-09 08:10:34 -04:00
|
|
|
database: 'knex_test',
|
2019-05-13 12:21:36 +03:00
|
|
|
user: 'testuser',
|
|
|
|
password: 'knextest',
|
2014-05-28 22:29:34 -04:00
|
|
|
},
|
2019-05-26 18:03:07 -07:00
|
|
|
pool,
|
|
|
|
migrations,
|
|
|
|
seeds,
|
2014-05-28 22:29:34 -04:00
|
|
|
},
|
2021-09-06 09:04:23 -04:00
|
|
|
|
2021-10-02 23:45:17 +03:00
|
|
|
cockroachdb: {
|
|
|
|
client: 'cockroachdb',
|
|
|
|
connection: testConfig.cockroachdb || {
|
|
|
|
adapter: 'cockroachdb',
|
|
|
|
port: 26257,
|
|
|
|
host: 'localhost',
|
|
|
|
database: 'test',
|
|
|
|
user: 'root',
|
|
|
|
password: undefined,
|
|
|
|
},
|
|
|
|
pool,
|
|
|
|
migrations,
|
|
|
|
seeds,
|
|
|
|
},
|
|
|
|
|
2021-09-06 09:04:23 -04:00
|
|
|
pgnative: {
|
|
|
|
client: 'pgnative',
|
|
|
|
connection: testConfig.pgnative || {
|
|
|
|
adapter: 'postgresql',
|
|
|
|
port: 25433,
|
|
|
|
host: 'localhost',
|
|
|
|
database: 'knex_test',
|
|
|
|
user: 'testuser',
|
|
|
|
password: 'knextest',
|
|
|
|
},
|
|
|
|
pool,
|
|
|
|
migrations,
|
|
|
|
seeds,
|
|
|
|
},
|
2014-05-28 22:29:34 -04:00
|
|
|
|
2018-02-03 08:33:02 -05:00
|
|
|
redshift: {
|
2018-07-08 14:10:51 +03:00
|
|
|
client: 'redshift',
|
2018-02-03 08:33:02 -05:00
|
|
|
connection: testConfig.redshift || {
|
2018-07-09 08:10:34 -04:00
|
|
|
adapter: 'postgresql',
|
2018-02-03 08:33:02 -05:00
|
|
|
database: 'knex_test',
|
2018-07-09 08:10:34 -04:00
|
|
|
user: process.env.REDSHIFT_USER || 'postgres',
|
2018-02-03 08:33:02 -05:00
|
|
|
password: process.env.REDSHIFT_PASSWORD || '',
|
2018-07-09 08:10:34 -04:00
|
|
|
port: '5439',
|
|
|
|
host: process.env.REDSHIFT_HOST || '127.0.0.1',
|
2018-02-03 08:33:02 -05:00
|
|
|
},
|
2019-05-26 18:03:07 -07:00
|
|
|
pool,
|
|
|
|
migrations,
|
|
|
|
seeds,
|
2018-02-03 08:33:02 -05:00
|
|
|
},
|
|
|
|
|
2014-05-28 22:29:34 -04:00
|
|
|
sqlite3: {
|
2018-08-29 17:13:16 +02:00
|
|
|
client: 'sqlite3',
|
2015-12-08 11:37:31 -06:00
|
|
|
connection: testConfig.sqlite3 || {
|
2018-07-09 08:10:34 -04:00
|
|
|
filename: __dirname + '/test.sqlite3',
|
2014-05-28 22:29:34 -04:00
|
|
|
},
|
2019-05-26 18:03:07 -07:00
|
|
|
pool: poolSqlite,
|
|
|
|
migrations,
|
|
|
|
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: {
|
2018-07-08 14:10:51 +03:00
|
|
|
client: 'mssql',
|
2015-12-14 11:10:46 -06:00
|
|
|
connection: testConfig.mssql || {
|
2018-07-09 08:10:34 -04:00
|
|
|
user: 'sa',
|
|
|
|
password: 'S0meVeryHardPassword',
|
|
|
|
server: 'localhost',
|
2019-05-13 12:21:36 +03:00
|
|
|
port: 21433,
|
2018-07-09 08:10:34 -04:00
|
|
|
database: 'knex_test',
|
2015-12-14 11:10:46 -06:00
|
|
|
},
|
|
|
|
pool: pool,
|
2019-05-26 18:03:07 -07:00
|
|
|
migrations,
|
|
|
|
seeds,
|
2018-07-09 08:10:34 -04: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
|
2018-07-09 08:10:34 -04:00
|
|
|
module.exports = _.reduce(
|
|
|
|
testIntegrationDialects,
|
2020-04-19 00:40:23 +02:00
|
|
|
function (res, dialectName) {
|
2018-07-09 08:10:34 -04:00
|
|
|
res[dialectName] = testConfigs[dialectName];
|
|
|
|
return res;
|
|
|
|
},
|
|
|
|
{}
|
|
|
|
);
|