music-collection/backend/src/database/database.config.ts
Phill Pover 513fd28d56
Some checks failed
Music Collection CI Workflow / deploy (push) Has been cancelled
Music Collection CI Workflow / test (./frontend) (push) Has been cancelled
Music Collection CI Workflow / build-and-push-images (./backend/Dockerfile, git.anatid.net/tabris/music-collection-backend, ./backend) (push) Has been cancelled
Music Collection CI Workflow / build-and-push-images (./frontend/Dockerfile, git.anatid.net/tabris/music-collection-frontend, ./frontend) (push) Has been cancelled
Music Collection CI Workflow / test (./backend) (push) Has been cancelled
Configuring multiple databases
2025-04-26 15:09:49 +01:00

47 lines
1.4 KiB
TypeScript

import { TypeOrmModuleOptions } from '@nestjs/typeorm';
import { ConfigService } from '@nestjs/config';
const configService = new ConfigService();
const commonConf = {
SYNCRONIZE: true,
ENTITIES: [__dirname + '/../**/*.entity{.ts,.js}'],
MIGRATIONS_RUN: false,
};
let databaseConfig: TypeOrmModuleOptions = {
type: 'sqlite',
database: './target/sqlite-dev-db.sql',
logging: true,
synchronize: true,
entities: commonConf.ENTITIES,
migrationsRun: commonConf.MIGRATIONS_RUN,
};
if (process.env.NODE_ENV === 'prod') {
databaseConfig = {
type: 'postgres',
host: configService.get<string>('database.host'),
port: configService.get<number>('database.port'),
username: configService.get<string>('database.user'),
password: configService.get<string>('database.password'),
database: configService.get<string>('database.name'),
logging: false,
synchronize: commonConf.SYNCRONIZE,
entities: commonConf.ENTITIES,
migrationsRun: commonConf.MIGRATIONS_RUN,
};
}
if (process.env.NODE_ENV === 'test') {
databaseConfig = {
type: 'sqlite',
database: ':memory:',
logging: true,
synchronize: true,
entities: commonConf.ENTITIES,
migrationsRun: commonConf.MIGRATIONS_RUN,
};
}
export { databaseConfig };