diff --git a/src/configs/mikro-orm.config.ts b/src/configs/mikro-orm.config.ts index f51843b..faef041 100755 --- a/src/configs/mikro-orm.config.ts +++ b/src/configs/mikro-orm.config.ts @@ -6,49 +6,46 @@ import { ConfigService } from "@nestjs/config"; import { MIKRO_ORM_QUERY_LOGGER, MikroOrmQueryLogger } from "../common/providers/mikro-orm-logger"; export const databaseConfig: MikroOrmModuleAsyncOptions = { - providers: [MikroOrmQueryLogger], inject: [ConfigService, MIKRO_ORM_QUERY_LOGGER], - driver: PostgreSqlDriver, - useFactory: (configService: ConfigService, logger: Logger) => ({ - driver: PostgreSqlDriver, - autoLoadEntities: true, - dbName: configService.getOrThrow("DB_NAME"), - user: configService.getOrThrow("DB_USER"), - password: configService.getOrThrow("DB_PASS"), - host: configService.getOrThrow("DB_HOST"), - port: configService.getOrThrow("DB_PORT"), - debug: configService.getOrThrow("NODE_ENV") !== "production", - ensureDatabase: { forceCheck: true, create: true, schema: "update" }, - // entities: ["./dist/**/*.entity.js"], - // entitiesTs: ["./src/**/*.entity.ts"], - forceUtcTimezone: true, - timezone: "UTC", - strict: true, - validate: true, - pool: { - min: 2, // Minimum number of connections in pool - max: 10, // Maximum number of connections in pool - idleTimeoutMillis: 30000, // 30 seconds before idle connection is closed - acquireTimeoutMillis: 10000, // 10 seconds to acquire a connection before throwing error - reapIntervalMillis: 1000, // How often to check for idle connections - createTimeoutMillis: 3000, // How long to wait when creating a new connection - destroyTimeoutMillis: 5000, // How long to wait when destroying a connection - }, - logger: (message) => logger.debug(message), - schemaGenerator: { - createForeignKey: true, - disableForeignKeys: false, - createIndex: true, - }, - migrations: { - path: "./database/migrations", - pathTs: "./database/migrations", - tableName: "migrations", - transactional: true, - allOrNothing: true, - dropTables: false, - safe: true, - emit: "ts", - }, - }), + providers: [MikroOrmQueryLogger], + useFactory: (configService: ConfigService, logger: Logger) => { + const DB_PASS = configService.getOrThrow("DB_PASS"); + const DB_USER = configService.getOrThrow("DB_USER"); + const DB_HOST = configService.getOrThrow("DB_HOST"); + const DB_PORT = configService.getOrThrow("DB_PORT"); + return { + driver: PostgreSqlDriver, + autoLoadEntities: true, + dbName: configService.getOrThrow("DB_NAME"), + debug: configService.get("NODE_ENV") !== "production", + clientUrl: `postgres://${DB_USER}:${DB_PASS}@${DB_HOST}:${DB_PORT}`, + ensureDatabase: { forceCheck: true, create: true, schema: "update" }, + forceUtcTimezone: true, + pool: { + min: 2, + max: 15, + idleTimeoutMillis: 10000, + acquireTimeoutMillis: 10000, + reapIntervalMillis: 1000, + createTimeoutMillis: 3000, + destroyTimeoutMillis: 5000, + }, + logger: (message) => logger.debug(message), + schemaGenerator: { + createForeignKey: true, + disableForeignKeys: false, + createIndex: true, + }, + migrations: { + path: "./database/migrations", + pathTs: "./database/migrations", + tableName: "migrations", + transactional: true, + allOrNothing: true, + dropTables: false, + safe: true, + emit: "ts", + }, + }; + }, };