Skip to content

Commit d348697

Browse files
committed
typeorm config
1 parent 7da5168 commit d348697

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

.env.example

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
# Authorization middleware
2-
IS_AUTHORIZATION=false
2+
IS_AUTHORIZATION=false
3+
4+
# Database
5+
DB_TYPE="postgres"
6+
DB_HOST=""
7+
DB_PORT=5432
8+
DB_USERNAME=""
9+
DB_PASSWORD=""
10+
DB_DATABASE=""

src/config/database.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { registerAs } from '@nestjs/config';
22
import { env } from 'process';
33

44
export default registerAs('database', () => ({
5-
type: 'postgres',
5+
type: process.env.DB_TYPE || '',
66
host: process.env.DB_HOST || '',
77
port: process.env.DB_PORT || 5432,
88
username: process.env.DB_USERNAME || '',

src/db/migrations/.gitkeeep

Whitespace-only changes.

src/setup/db/data-source.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ConfigService } from '@nestjs/config';
2+
import { DataSource } from 'typeorm';
3+
import * as dotenv from 'dotenv';
4+
5+
declare let process : {
6+
env: any
7+
};
8+
9+
dotenv.config();
10+
11+
export const dataSource = new DataSource({
12+
migrationsTableName: 'migrations',
13+
type: process.env.DB_TYPE || '',
14+
host: process.env.DB_HOST || '',
15+
port: process.env.DB_PORT || 5432,
16+
username: process.env.DB_USERNAME || '',
17+
password: process.env.DB_PASSWORD || '',
18+
database: process.env.DB_DATABASE || '',
19+
synchronize: false,
20+
logging: false,
21+
entities: ['src/**/*.entity.ts'],
22+
migrations: ['src/db/migrations/*.ts'],
23+
});

src/setup/db/database.setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function database() : any {
1414
entities: ['dist/**/*.entity{.ts,.js}'],
1515
cli: {
1616
entitiesDir: 'src/**/*entity{.ts,.js}',
17-
migrationsDir: 'src/migration',
17+
migrationsDir: 'src/db/migrations',
1818
},
1919
synchronize: false,
2020
}),

0 commit comments

Comments
 (0)