chore(): Add support for extra pool configuration (#11636)
**What** Support more pool configuration
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/framework": patch
|
||||||
|
"@medusajs/utils": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
chore(): Add support for extra pool configuration
|
||||||
@@ -19,12 +19,16 @@ export function pgConnectionLoader(): ReturnType<
|
|||||||
|
|
||||||
// Share a knex connection to be consumed by the shared modules
|
// Share a knex connection to be consumed by the shared modules
|
||||||
const connectionString = configModule.projectConfig.databaseUrl
|
const connectionString = configModule.projectConfig.databaseUrl
|
||||||
const driverOptions: any =
|
const driverOptions: any = {
|
||||||
configModule.projectConfig.databaseDriverOptions || {}
|
...(configModule.projectConfig.databaseDriverOptions || {}),
|
||||||
|
}
|
||||||
const schema = configModule.projectConfig.databaseSchema || "public"
|
const schema = configModule.projectConfig.databaseSchema || "public"
|
||||||
const idleTimeoutMillis = driverOptions.pool?.idleTimeoutMillis ?? undefined // prevent null to be passed
|
const idleTimeoutMillis = driverOptions.pool?.idleTimeoutMillis ?? undefined // prevent null to be passed
|
||||||
const poolMin = driverOptions.pool?.min ?? 2
|
const poolMin = driverOptions.pool?.min ?? 2
|
||||||
const poolMax = driverOptions.pool?.max
|
const poolMax = driverOptions.pool?.max
|
||||||
|
const reapIntervalMillis = driverOptions.pool?.reapIntervalMillis ?? undefined
|
||||||
|
const createRetryIntervalMillis =
|
||||||
|
driverOptions.pool?.createRetryIntervalMillis ?? undefined
|
||||||
|
|
||||||
delete driverOptions.pool
|
delete driverOptions.pool
|
||||||
|
|
||||||
@@ -36,6 +40,8 @@ export function pgConnectionLoader(): ReturnType<
|
|||||||
min: poolMin,
|
min: poolMin,
|
||||||
max: poolMax,
|
max: poolMax,
|
||||||
idleTimeoutMillis,
|
idleTimeoutMillis,
|
||||||
|
reapIntervalMillis,
|
||||||
|
createRetryIntervalMillis,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -115,6 +115,10 @@ export class MedusaAppLoader {
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const driverOptions = { ...(configManager.config.projectConfig.databaseDriverOptions ?? {}) }
|
||||||
|
const pool = driverOptions.pool ?? {}
|
||||||
|
delete driverOptions.pool
|
||||||
|
|
||||||
const sharedResourcesConfig: ModuleServiceInitializeOptions = {
|
const sharedResourcesConfig: ModuleServiceInitializeOptions = {
|
||||||
database: {
|
database: {
|
||||||
clientUrl:
|
clientUrl:
|
||||||
@@ -125,6 +129,7 @@ export class MedusaAppLoader {
|
|||||||
)?.client?.config?.connection?.connectionString ??
|
)?.client?.config?.connection?.connectionString ??
|
||||||
configManager.config.projectConfig.databaseUrl,
|
configManager.config.projectConfig.databaseUrl,
|
||||||
driverOptions: configManager.config.projectConfig.databaseDriverOptions,
|
driverOptions: configManager.config.projectConfig.databaseDriverOptions,
|
||||||
|
pool: pool,
|
||||||
debug: configManager.config.projectConfig.databaseLogging ?? false,
|
debug: configManager.config.projectConfig.databaseLogging ?? false,
|
||||||
schema: configManager.config.projectConfig.databaseSchema,
|
schema: configManager.config.projectConfig.databaseSchema,
|
||||||
database: configManager.config.projectConfig.databaseName,
|
database: configManager.config.projectConfig.databaseName,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export function createPgConnection(options: Options) {
|
|||||||
pool: {
|
pool: {
|
||||||
// https://knexjs.org/guide/#pool
|
// https://knexjs.org/guide/#pool
|
||||||
...(pool ?? {}),
|
...(pool ?? {}),
|
||||||
min: (pool?.min as number) ?? 2,
|
min: (pool?.min as number) ?? 1,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ export function loadDatabaseConfig(
|
|||||||
const clientUrl =
|
const clientUrl =
|
||||||
options?.database?.clientUrl ?? getEnv("DATABASE_URL", moduleName)
|
options?.database?.clientUrl ?? getEnv("DATABASE_URL", moduleName)
|
||||||
|
|
||||||
|
const poolEnvConfig = getEnv("DATABASE_POOL", moduleName)
|
||||||
const database = {
|
const database = {
|
||||||
clientUrl,
|
clientUrl,
|
||||||
schema: getEnv("DATABASE_SCHEMA", moduleName) ?? "public",
|
schema: getEnv("DATABASE_SCHEMA", moduleName) ?? "public",
|
||||||
@@ -79,6 +80,7 @@ export function loadDatabaseConfig(
|
|||||||
getEnv("DATABASE_DRIVER_OPTIONS", moduleName) ||
|
getEnv("DATABASE_DRIVER_OPTIONS", moduleName) ||
|
||||||
JSON.stringify(getDefaultDriverOptions(clientUrl))
|
JSON.stringify(getDefaultDriverOptions(clientUrl))
|
||||||
),
|
),
|
||||||
|
pool: poolEnvConfig ? JSON.parse(poolEnvConfig) : undefined,
|
||||||
debug: false,
|
debug: false,
|
||||||
connection: undefined,
|
connection: undefined,
|
||||||
}
|
}
|
||||||
@@ -91,6 +93,7 @@ export function loadDatabaseConfig(
|
|||||||
database.driverOptions =
|
database.driverOptions =
|
||||||
options.database!.driverOptions ??
|
options.database!.driverOptions ??
|
||||||
getDefaultDriverOptions(database.clientUrl)
|
getDefaultDriverOptions(database.clientUrl)
|
||||||
|
database.pool = options.database!.pool ?? database.pool
|
||||||
database.debug = options.database!.debug ?? database.debug
|
database.debug = options.database!.debug ?? database.debug
|
||||||
database.connection = options.database!.connection
|
database.connection = options.database!.connection
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user