Skip to content

Commit

Permalink
feat: added Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mvegter committed Apr 28, 2020
1 parent b3301c7 commit 57655be
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 8 deletions.
48 changes: 48 additions & 0 deletions lib/config/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

// Default configuration
let dialect = 'mariadb';
let host = 'localhost';
let username = 'cern';
let password = 'cern';
let database = 'bookkeeping';

// Default environment specific override
if (process.env.NODE_ENV === 'test') {
host = 'database';
}

if (process.env.DATABASE_HOST) {
host = process.env.DATABASE_HOST;
}

if (process.env.DATABASE_USERNAME) {
username = process.env.DATABASE_USERNAME;
}

if (process.env.DATABASE_PASSWORD) {
password = process.env.DATABASE_PASSWORD;
}

if (process.env.DATABASE_NAME) {
database = process.env.DATABASE_NAME;
}

module.exports = {
dialect,
host,
username,
password,
database,
};
18 changes: 18 additions & 0 deletions lib/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

const database = require('./database');

module.exports = {
database,
};
12 changes: 4 additions & 8 deletions lib/database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const path = require('path');
const { Sequelize } = require('sequelize');
const Umzug = require('umzug');
const { Database } = require('../application/interfaces');
const { database: Config } = require('../config');

/**
* Sequelize implementation of the Database interface.
Expand All @@ -26,14 +27,9 @@ class SequelizeDatabase extends Database {
constructor() {
super();

let host = process.env.DATABASE_HOST || 'localhost';
if (process.env.NODE_ENV === 'test') {
host = 'database';
}

this.sequelize = new Sequelize('bookkeeping', 'cern', 'cern', {
host,
dialect: 'mariadb',
this.sequelize = new Sequelize(Config.database, Config.username, Config.password, {
host: Config.host,
dialect: Config.dialect,
});
}

Expand Down

0 comments on commit 57655be

Please sign in to comment.