chore: Deprecate extra in favor of driver options (#6772)
**What** Deprecate databse_extra in favor of database_driver_options Co-authored-by: Sebastian Rindom <7554214+srindom@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
56481e683d
commit
1ef9c78cea
8
.changeset/violet-lizards-help.md
Normal file
8
.changeset/violet-lizards-help.md
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
"medusa-test-utils": patch
|
||||
"@medusajs/types": patch
|
||||
"@medusajs/utils": patch
|
||||
---
|
||||
|
||||
chore: v2 - deprecate extra in favor of driver options
|
||||
@@ -15,6 +15,7 @@ const { logger } = require("@medusajs/medusa-cli/dist/reporter")
|
||||
module.exports = {
|
||||
initDb: async function ({
|
||||
cwd,
|
||||
// use for v1 datasource only
|
||||
database_extra,
|
||||
env,
|
||||
force_modules_migration,
|
||||
|
||||
@@ -8,15 +8,15 @@ import {
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
FlagRouter,
|
||||
MedusaV2Flag,
|
||||
isObject,
|
||||
MedusaV2Flag,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
MODULE_PACKAGE_NAMES,
|
||||
MedusaApp,
|
||||
MedusaAppMigrateUp,
|
||||
MedusaAppOutput,
|
||||
MedusaModule,
|
||||
MODULE_PACKAGE_NAMES,
|
||||
Modules,
|
||||
ModulesDefinition,
|
||||
} from "@medusajs/modules-sdk"
|
||||
@@ -71,7 +71,7 @@ export async function migrateMedusaApp(
|
||||
injectedDependencies[ContainerRegistrationKeys.PG_CONNECTION]?.client
|
||||
?.config?.connection?.connectionString ??
|
||||
configModule.projectConfig.database_url,
|
||||
driverOptions: configModule.projectConfig.database_extra,
|
||||
driverOptions: configModule.projectConfig.database_driver_options,
|
||||
debug: !!(configModule.projectConfig.database_logging ?? false),
|
||||
},
|
||||
}
|
||||
@@ -136,7 +136,7 @@ export const loadMedusaApp = async (
|
||||
const sharedResourcesConfig = {
|
||||
database: {
|
||||
clientUrl: configModule.projectConfig.database_url,
|
||||
driverOptions: configModule.projectConfig.database_extra,
|
||||
driverOptions: configModule.projectConfig.database_driver_options,
|
||||
debug: !!(configModule.projectConfig.database_logging ?? false),
|
||||
},
|
||||
}
|
||||
@@ -262,7 +262,7 @@ export async function runModulesLoader({
|
||||
const sharedResourcesConfig = {
|
||||
database: {
|
||||
clientUrl: configModule.projectConfig.database_url,
|
||||
driverOptions: configModule.projectConfig.database_extra,
|
||||
driverOptions: configModule.projectConfig.database_driver_options,
|
||||
debug: !!(configModule.projectConfig.database_logging ?? false),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -14,18 +14,18 @@ export default async ({ container, configModule }: Options): Promise<any> => {
|
||||
|
||||
// Share a knex connection to be consumed by the shared modules
|
||||
const connectionString = configModule.projectConfig.database_url
|
||||
const extra: any = configModule.projectConfig.database_extra || {}
|
||||
const driverOptions: any =
|
||||
configModule.projectConfig.database_driver_options || {}
|
||||
const schema = configModule.projectConfig.database_schema || "public"
|
||||
const idleTimeoutMillis = extra.idleTimeoutMillis ?? undefined // prevent null to be passed
|
||||
const poolMax = extra.max
|
||||
const idleTimeoutMillis = driverOptions.pool?.idleTimeoutMillis ?? undefined // prevent null to be passed
|
||||
const poolMax = driverOptions.pool?.max
|
||||
|
||||
delete extra.max
|
||||
delete extra.idleTimeoutMillis
|
||||
delete driverOptions.pool
|
||||
|
||||
const pgConnection = ModulesSdkUtils.createPgConnection({
|
||||
clientUrl: connectionString,
|
||||
schema,
|
||||
driverOptions: extra,
|
||||
driverOptions,
|
||||
pool: {
|
||||
max: poolMax,
|
||||
idleTimeoutMillis,
|
||||
|
||||
@@ -355,6 +355,41 @@ export type ProjectConfigOptions = {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An object that includes additional configurations to pass to the database connection for v2. You can pass any configuration. One defined configuration to pass is
|
||||
* `ssl` which enables support for TLS/SSL connections.
|
||||
*
|
||||
* This is useful for production databases, which can be supported by setting the `rejectUnauthorized` attribute of `ssl` object to `false`.
|
||||
* During development, it’s recommended not to pass this option.
|
||||
*
|
||||
* @example
|
||||
* ```js title="medusa-config.js"
|
||||
* module.exports = {
|
||||
* projectConfig: {
|
||||
* database_driver_options:
|
||||
* process.env.NODE_ENV !== "development"
|
||||
* ? { connection: { ssl: { rejectUnauthorized: false } } }
|
||||
* : {},
|
||||
* // ...
|
||||
* },
|
||||
* // ...
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
database_driver_options?: Record<string, unknown> & {
|
||||
connection?: {
|
||||
/**
|
||||
* Configure support for TLS/SSL connection
|
||||
*/
|
||||
ssl?: {
|
||||
/**
|
||||
* Whether to fail connection if the server certificate is verified against the list of supplied CAs and the hostname and no match is found.
|
||||
*/
|
||||
rejectUnauthorized?: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to specify the URL to connect to Redis. This is only used for scheduled jobs. If you omit this configuration, scheduled jobs won't work.
|
||||
*
|
||||
|
||||
@@ -254,7 +254,9 @@ export interface ModuleServiceInitializeOptions {
|
||||
user?: string
|
||||
password?: string
|
||||
database?: string
|
||||
driverOptions?: Record<string, unknown>
|
||||
driverOptions?: Record<string, unknown> & {
|
||||
connection?: Record<string, unknown>
|
||||
}
|
||||
debug?: boolean
|
||||
pool?: Record<string, unknown>
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ export async function mikroOrmCreateConnection(
|
||||
let schema = database.schema || "public"
|
||||
|
||||
let driverOptions = database.driverOptions ?? {
|
||||
connection: { ssl: true },
|
||||
connection: { ssl: false },
|
||||
}
|
||||
|
||||
let clientUrl = database.clientUrl
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { knex } from "@mikro-orm/knex"
|
||||
import { ModuleServiceInitializeOptions } from "@medusajs/types"
|
||||
import { isDefined } from "../common"
|
||||
|
||||
type Options = ModuleServiceInitializeOptions["database"]
|
||||
|
||||
@@ -9,7 +10,10 @@ type Options = ModuleServiceInitializeOptions["database"]
|
||||
*/
|
||||
export function createPgConnection(options: Options) {
|
||||
const { pool, schema = "public", clientUrl, driverOptions } = options
|
||||
const ssl = options.driverOptions?.ssl ?? false
|
||||
const ssl =
|
||||
options.driverOptions?.ssl ??
|
||||
options.driverOptions?.connection?.ssl ??
|
||||
false
|
||||
|
||||
return knex<any, any>({
|
||||
client: "pg",
|
||||
|
||||
Reference in New Issue
Block a user