-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: adding env to configuration service
- Loading branch information
1 parent
1a3ff49
commit 2e5e7c3
Showing
11 changed files
with
55 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
import { Client } from 'pg'; | ||
import { Sequelize } from 'sequelize-typescript'; | ||
import * as cls from 'cls-hooked'; | ||
import { IS_DEV } from './env'; | ||
import { configLoader } from './config'; | ||
|
||
const logger = global.LOGGER(); | ||
|
||
const IS_DEV = process.env.NODE_ENV === 'development'; | ||
const globalConfig = configLoader.getGlobalConfig(); | ||
|
||
const DATABASE_URL = | ||
process.env.DATABASE_URL || | ||
'postgres://paraswap:[email protected]:32780/volume_tracker'; | ||
const logger = global.LOGGER(); | ||
|
||
const DATABASE_NAME = process.env.DATABASE_NAME || 'volume_tracker'; | ||
const DATABASE_NAME = 'volume_tracker'; | ||
|
||
export class Database { | ||
sequelize: Sequelize; | ||
|
@@ -22,14 +20,16 @@ export class Database { | |
} | ||
|
||
// create a volume-tracker DB if it doesn't exist already | ||
const connectionStringParts = DATABASE_URL.split('/'); | ||
const connectionStringParts = globalConfig.databaseUrl.split('/'); | ||
const connectionStringDBName = | ||
connectionStringParts[connectionStringParts.length - 1]; | ||
if (connectionStringDBName !== DATABASE_NAME) { | ||
logger.info( | ||
'Database name in connection string is different than expected', | ||
); | ||
const client = new Client({ connectionString: DATABASE_URL }); | ||
|
||
console.log(globalConfig.databaseUrl); | ||
const client = new Client({ connectionString: globalConfig.databaseUrl }); | ||
await client.connect(); | ||
try { | ||
await client.query(`CREATE DATABASE ${DATABASE_NAME};`); | ||
|
@@ -62,7 +62,7 @@ export class Database { | |
}); | ||
|
||
try { | ||
logger.info('Connecting to database...'); | ||
logger.info('Connecting to database...', connectionStringDBName); | ||
await this.sequelize.authenticate(); | ||
logger.info('Connected to database'); | ||
} catch (e) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters