1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

options to specify different db-schema

This commit is contained in:
ivaosthu 2016-11-12 11:21:40 +01:00 committed by Ivar Conradi Østhus
parent bc8b1d572a
commit 14deebae1f
7 changed files with 26 additions and 15 deletions

4
app.js
View File

@ -21,10 +21,10 @@ module.exports = function (config) {
app.locals.baseUriPath = baseUriPath;
app.use(cookieParser());
if (publicFolder) {
/* if (publicFolder) {
app.use(favicon(path.join(publicFolder, 'favicon.ico')));
}
*/
app.use(validator([]));
if (publicFolder) {
app.use(baseUriPath, express.static(publicFolder));

View File

@ -2,10 +2,13 @@
const knex = require('knex');
module.exports.createDb = function (databaseConnection) {
return knex({
module.exports.createDb = function (databaseConnection, schema = 'public') {
const db = knex({
client: 'pg',
connection: databaseConnection,
pool: { min: 2, max: 20 },
searchPath: schema,
});
return db;
};

View File

@ -9,7 +9,7 @@ const ClientMetricsStore = require('./client-metrics-store');
const ClientStrategyStore = require('./client-strategy-store');
module.exports.createStores = (config) => {
const db = createDb(config.databaseUri);
const db = createDb(config.databaseUri, config.databaseSchema);
const eventStore = new EventStore(db);
return {

View File

@ -2,12 +2,14 @@
const DBMigrate = require('db-migrate');
const path = require('path');
const parseDbUrl = require('parse-database-url');
function migrateDb (dbUri) {
console.log(dbUri);
function migrateDb (dbUrl, schema = "public") {
const custom = parseDbUrl(dbUrl);
custom.schema = schema;
const dbmigrate = DBMigrate.getInstance(true, {
cwd: __dirname,
config: { "custom": dbUri},
config: { custom },
env: 'custom' }
);
return dbmigrate.up();

View File

@ -63,6 +63,7 @@
"knex": "^0.12.6",
"log4js": "^1.0.1",
"moment": "^2.15.2",
"parse-database-url": "^0.3.0",
"pg": "^6.1.0",
"serve-favicon": "^2.3.0",
"unleash-frontend": "github:unleash/unleash-frontend",

View File

@ -4,7 +4,6 @@ function getDatabaseUri () {
if (process.env.TEST_DATABASE_URL) {
return process.env.TEST_DATABASE_URL;
} else {
console.log('Using default unleash_test database');
return 'postgres://unleash_user:passord@localhost:5432/unleash_test';
}
}

View File

@ -6,18 +6,24 @@ let supertest = require('supertest');
const options = {
databaseUri: require('./database-config').getDatabaseUri(),
databaseSchema: 'test'
};
const migrator = require('../../../migrator');
const { createStores } = require('../../../lib/db');
process.env.DATABASE_URL = options.databaseUri
// because of migrator bug
delete process.env.DATABASE_URL;
const createApp = migrator(options.databaseUri).then(() => {
const stores = createStores(options);
const app = require('../../../app')({stores});
return { stores, request: supertest(app) };
});
const db = require('../../../lib/db/db-pool').createDb(options.databaseUri);
const createApp = db.raw(`CREATE SCHEMA IF NOT EXISTS ${options.databaseSchema}`)
.then(() => migrator(options.databaseUri, options.databaseSchema))
.then(() => {
const stores = createStores(options);
const app = require('../../../app')({stores});
return { stores, request: supertest(app) };
});
function createStrategies (stores) {
return [