-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update ormConfig and add datasourceConfig
- Loading branch information
1 parent
e3df2e2
commit 0911505
Showing
3 changed files
with
53 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { DataSource, DataSourceOptions } from 'typeorm'; | ||
import { MysqlConnectionCredentialsOptions } from 'typeorm/driver/mysql/MysqlConnectionCredentialsOptions'; | ||
import * as dotenv from 'dotenv'; | ||
import * as dotenvExpand from 'dotenv-expand'; | ||
|
||
dotenvExpand.expand(dotenv.config()); | ||
|
||
const db: MysqlConnectionCredentialsOptions = { | ||
host: process.env.DB_HOST, | ||
port: parseInt(process.env.DB_PORT), | ||
username: process.env.DB_USERNAME, | ||
password: process.env.DB_PASSWORD, | ||
database: process.env.DB_NAME, | ||
}; | ||
|
||
const dbSlaves = process.env.DB_SLAVES | ||
? JSON.parse(process.env.DB_SLAVES) | ||
: [db]; | ||
const connectionSource = new DataSource({ | ||
migrationsTableName: 'migrations', | ||
type: 'mysql', | ||
host: process.env.DB_HOST, | ||
port: parseInt(process.env.DB_PORT), | ||
username: process.env.DB_USERNAME, | ||
password: process.env.DB_PASSWORD, | ||
database: process.env.DB_NAME, | ||
logging: process.env.DB_LOGGING, | ||
synchronize: false, | ||
replication: { | ||
master: db, | ||
slaves: dbSlaves, | ||
}, | ||
entities: | ||
process.env.NODE_ENV === 'test-e2e' | ||
? ['src/db/**/*.entity.js'] | ||
: ['dist/db/**/*.entity.js'], | ||
migrations: ['dist/db/migrations/*.js'], | ||
extra: { | ||
connectionLimit: process.env.DB_CONNECTION_LIMIT, | ||
ssl: { | ||
rejectUnauthorized: false, | ||
}, | ||
}, | ||
} as DataSourceOptions); | ||
|
||
export default connectionSource; |
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