1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-01 00:08:27 +01:00

Merge pull request #167 from Unleash/db_schemas

options to specify different db-schema
This commit is contained in:
Sveinung Røsaker 2016-11-12 11:27:05 +01:00 committed by GitHub
commit a1837d90d4
6 changed files with 24 additions and 13 deletions

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 [