Update mikro-orm.config.ts

This commit is contained in:
Mahyar
2025-05-13 09:40:21 +03:30
committed by GitHub
parent 77c0f59514
commit 474193ef4e
+41 -44
View File
@@ -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<string>("DB_NAME"),
user: configService.getOrThrow<string>("DB_USER"),
password: configService.getOrThrow<string>("DB_PASS"),
host: configService.getOrThrow<string>("DB_HOST"),
port: configService.getOrThrow<number>("DB_PORT"),
debug: configService.getOrThrow<string>("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<string>("DB_PASS");
const DB_USER = configService.getOrThrow<string>("DB_USER");
const DB_HOST = configService.getOrThrow<string>("DB_HOST");
const DB_PORT = configService.getOrThrow<number>("DB_PORT");
return {
driver: PostgreSqlDriver,
autoLoadEntities: true,
dbName: configService.getOrThrow<string>("DB_NAME"),
debug: configService.get<string>("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",
},
};
},
};