chore(): Add support for extra pool configuration (#11636)
**What** Support more pool configuration
This commit is contained in:
committed by
GitHub
parent
d493347980
commit
ca6a15717d
6
.changeset/healthy-phones-worry.md
Normal file
6
.changeset/healthy-phones-worry.md
Normal file
@@ -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
|
||||
const connectionString = configModule.projectConfig.databaseUrl
|
||||
const driverOptions: any =
|
||||
configModule.projectConfig.databaseDriverOptions || {}
|
||||
const driverOptions: any = {
|
||||
...(configModule.projectConfig.databaseDriverOptions || {}),
|
||||
}
|
||||
const schema = configModule.projectConfig.databaseSchema || "public"
|
||||
const idleTimeoutMillis = driverOptions.pool?.idleTimeoutMillis ?? undefined // prevent null to be passed
|
||||
const poolMin = driverOptions.pool?.min ?? 2
|
||||
const poolMax = driverOptions.pool?.max
|
||||
const reapIntervalMillis = driverOptions.pool?.reapIntervalMillis ?? undefined
|
||||
const createRetryIntervalMillis =
|
||||
driverOptions.pool?.createRetryIntervalMillis ?? undefined
|
||||
|
||||
delete driverOptions.pool
|
||||
|
||||
@@ -36,6 +40,8 @@ export function pgConnectionLoader(): ReturnType<
|
||||
min: poolMin,
|
||||
max: poolMax,
|
||||
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 = {
|
||||
database: {
|
||||
clientUrl:
|
||||
@@ -125,6 +129,7 @@ export class MedusaAppLoader {
|
||||
)?.client?.config?.connection?.connectionString ??
|
||||
configManager.config.projectConfig.databaseUrl,
|
||||
driverOptions: configManager.config.projectConfig.databaseDriverOptions,
|
||||
pool: pool,
|
||||
debug: configManager.config.projectConfig.databaseLogging ?? false,
|
||||
schema: configManager.config.projectConfig.databaseSchema,
|
||||
database: configManager.config.projectConfig.databaseName,
|
||||
|
||||
@@ -27,7 +27,7 @@ export function createPgConnection(options: Options) {
|
||||
pool: {
|
||||
// https://knexjs.org/guide/#pool
|
||||
...(pool ?? {}),
|
||||
min: (pool?.min as number) ?? 2,
|
||||
min: (pool?.min as number) ?? 1,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@ export function loadDatabaseConfig(
|
||||
const clientUrl =
|
||||
options?.database?.clientUrl ?? getEnv("DATABASE_URL", moduleName)
|
||||
|
||||
const poolEnvConfig = getEnv("DATABASE_POOL", moduleName)
|
||||
const database = {
|
||||
clientUrl,
|
||||
schema: getEnv("DATABASE_SCHEMA", moduleName) ?? "public",
|
||||
@@ -79,6 +80,7 @@ export function loadDatabaseConfig(
|
||||
getEnv("DATABASE_DRIVER_OPTIONS", moduleName) ||
|
||||
JSON.stringify(getDefaultDriverOptions(clientUrl))
|
||||
),
|
||||
pool: poolEnvConfig ? JSON.parse(poolEnvConfig) : undefined,
|
||||
debug: false,
|
||||
connection: undefined,
|
||||
}
|
||||
@@ -91,6 +93,7 @@ export function loadDatabaseConfig(
|
||||
database.driverOptions =
|
||||
options.database!.driverOptions ??
|
||||
getDefaultDriverOptions(database.clientUrl)
|
||||
database.pool = options.database!.pool ?? database.pool
|
||||
database.debug = options.database!.debug ?? database.debug
|
||||
database.connection = options.database!.connection
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user