Skip to content

Commit

Permalink
#30 - Changed circleci config.
Browse files Browse the repository at this point in the history
  • Loading branch information
douglascvas committed Sep 4, 2018
1 parent 7dae064 commit 80d9e78
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion backend/src/main/database/DatabaseManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class DatabaseManager {
port: process.env.MYSQL_PORT || 3306,
user: process.env.MYSQL_USER || 'root',
password: process.env.MYSQL_PW || 'admin',
database: process.env.MYSQL_DB,
database: process.env.MYSQL_DB || 'carpal',
multipleStatements: true
};
}
Expand Down
22 changes: 16 additions & 6 deletions backend/src/main/database/RefreshDatabase.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const fs = require('fs');
const path = require('path');
const DatabaseManager = require('./DatabaseManager');

const createDB = '2018-08-04-1-create-database.sql';
const changeSet = [
'2018-08-04-1-create-database.sql',
'2018-08-04-2-create-location-table.sql',
'2018-08-04-3-create-rides-table.sql',
'2018-08-04-4-create-driver-table.sql',
Expand All @@ -12,18 +13,27 @@ const changeSet = [

class RefreshDatabase {
constructor(databaseManager) {
const dbConfig = Object.assign({}, databaseManager.databaseConfig);

delete dbConfig.database;
this.databaseManagerNoDb = new DatabaseManager(dbConfig);
this.databaseManager = databaseManager;
}

async executeAll() {
for (let fileName of changeSet) {
await this.execute(fileName);
}
this.execute(createDB, this.databaseManagerNoDb)
.then(() => {
let result = Promise.resolve();
changeSet.forEach(fileName => {
result = result.then(this.execute(fileName, this.databaseManager))
});
return result;
})
}

async execute(fileName) {
execute(fileName, databaseManager) {
let sql = fs.readFileSync(path.resolve(__dirname, './changes/' + fileName)).toString().trim();
return this.databaseManager.query(sql);
return databaseManager.query(sql);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CREATE DATABASE IF NOT EXISTS carpal;
CREATE SCHEMA IF NOT EXISTS carpal;

0 comments on commit 80d9e78

Please sign in to comment.