Update mikro-orm.config.ts
This commit is contained in:
@@ -6,33 +6,29 @@ import { ConfigService } from "@nestjs/config";
|
|||||||
import { MIKRO_ORM_QUERY_LOGGER, MikroOrmQueryLogger } from "../common/providers/mikro-orm-logger";
|
import { MIKRO_ORM_QUERY_LOGGER, MikroOrmQueryLogger } from "../common/providers/mikro-orm-logger";
|
||||||
|
|
||||||
export const databaseConfig: MikroOrmModuleAsyncOptions = {
|
export const databaseConfig: MikroOrmModuleAsyncOptions = {
|
||||||
providers: [MikroOrmQueryLogger],
|
|
||||||
inject: [ConfigService, MIKRO_ORM_QUERY_LOGGER],
|
inject: [ConfigService, MIKRO_ORM_QUERY_LOGGER],
|
||||||
driver: PostgreSqlDriver,
|
providers: [MikroOrmQueryLogger],
|
||||||
useFactory: (configService: ConfigService, logger: Logger) => ({
|
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,
|
driver: PostgreSqlDriver,
|
||||||
autoLoadEntities: true,
|
autoLoadEntities: true,
|
||||||
dbName: configService.getOrThrow<string>("DB_NAME"),
|
dbName: configService.getOrThrow<string>("DB_NAME"),
|
||||||
user: configService.getOrThrow<string>("DB_USER"),
|
debug: configService.get<string>("NODE_ENV") !== "production",
|
||||||
password: configService.getOrThrow<string>("DB_PASS"),
|
clientUrl: `postgres://${DB_USER}:${DB_PASS}@${DB_HOST}:${DB_PORT}`,
|
||||||
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" },
|
ensureDatabase: { forceCheck: true, create: true, schema: "update" },
|
||||||
// entities: ["./dist/**/*.entity.js"],
|
|
||||||
// entitiesTs: ["./src/**/*.entity.ts"],
|
|
||||||
forceUtcTimezone: true,
|
forceUtcTimezone: true,
|
||||||
timezone: "UTC",
|
|
||||||
strict: true,
|
|
||||||
validate: true,
|
|
||||||
pool: {
|
pool: {
|
||||||
min: 2, // Minimum number of connections in pool
|
min: 2,
|
||||||
max: 10, // Maximum number of connections in pool
|
max: 15,
|
||||||
idleTimeoutMillis: 30000, // 30 seconds before idle connection is closed
|
idleTimeoutMillis: 10000,
|
||||||
acquireTimeoutMillis: 10000, // 10 seconds to acquire a connection before throwing error
|
acquireTimeoutMillis: 10000,
|
||||||
reapIntervalMillis: 1000, // How often to check for idle connections
|
reapIntervalMillis: 1000,
|
||||||
createTimeoutMillis: 3000, // How long to wait when creating a new connection
|
createTimeoutMillis: 3000,
|
||||||
destroyTimeoutMillis: 5000, // How long to wait when destroying a connection
|
destroyTimeoutMillis: 5000,
|
||||||
},
|
},
|
||||||
logger: (message) => logger.debug(message),
|
logger: (message) => logger.debug(message),
|
||||||
schemaGenerator: {
|
schemaGenerator: {
|
||||||
@@ -50,5 +46,6 @@ export const databaseConfig: MikroOrmModuleAsyncOptions = {
|
|||||||
safe: true,
|
safe: true,
|
||||||
emit: "ts",
|
emit: "ts",
|
||||||
},
|
},
|
||||||
}),
|
};
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user