32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from '@nestjs/typeorm';
|
|
import { SnakeNamingStrategy } from "typeorm-naming-strategies"
|
|
|
|
|
|
|
|
@Injectable()
|
|
export class DatabaseOptions implements TypeOrmOptionsFactory {
|
|
constructor(private config: ConfigService) { }
|
|
|
|
createTypeOrmOptions(): TypeOrmModuleOptions | Promise<TypeOrmModuleOptions> {
|
|
return {
|
|
type: "postgres",
|
|
host: this.config.getOrThrow('DATABASE_HOST'),
|
|
port: parseInt(this.config.getOrThrow('DATABASE_PORT'), 10),
|
|
username: this.config.getOrThrow('DATABASE_USERNAME'),
|
|
password: this.config.getOrThrow('DATABASE_PASSWORD'),
|
|
database: this.config.getOrThrow('DATABASE_NAME'),
|
|
|
|
entities: [__dirname + '/../**/*.entity.js'],
|
|
logging: true,
|
|
synchronize: false,
|
|
//migrations: ['dist/migrations/*.ts'],
|
|
// cli: {
|
|
// migrationsDir: process.env.TYPEORM_MIGRATIONS_DIR,
|
|
// },
|
|
namingStrategy: new SnakeNamingStrategy(),
|
|
};
|
|
}
|
|
}
|