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('database.host'), port: configService.get('database.port'), username: configService.get('database.user'), password: configService.get('database.password'), database: configService.get('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 };