fix(utils,product): mikro orm connection loader (#4825)
Fix shared connection property check
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/utils": minor
|
||||||
|
"@medusajs/product": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix mikro-orm connection loader
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import dbFactory from "./../../../environment-helpers/use-template-db"
|
||||||
|
|
||||||
|
jest.setTimeout(30000)
|
||||||
|
|
||||||
|
describe("Standalone Modules", () => {
|
||||||
|
beforeAll(async () => {
|
||||||
|
const DB_HOST = process.env.DB_HOST
|
||||||
|
const DB_USERNAME = process.env.DB_USERNAME
|
||||||
|
const DB_PASSWORD = process.env.DB_PASSWORD
|
||||||
|
const DB_NAME = process.env.DB_TEMP_NAME
|
||||||
|
|
||||||
|
process.env.POSTGRES_URL = `postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}`
|
||||||
|
await dbFactory.createFromTemplate(DB_NAME)
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
process.env.POSTGRES_URL = undefined
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Should migrate database and initialize Product module using connection string from environment variable ", async function () {
|
||||||
|
const { initialize, runMigrations } = require("@medusajs/product")
|
||||||
|
await runMigrations()
|
||||||
|
|
||||||
|
const product = await initialize()
|
||||||
|
const productList = await product.list()
|
||||||
|
|
||||||
|
expect(productList).toEqual(expect.arrayContaining([]))
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -5,11 +5,11 @@ import {
|
|||||||
MODULE_SCOPE,
|
MODULE_SCOPE,
|
||||||
ModulesSdkTypes,
|
ModulesSdkTypes,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import { asValue } from "awilix"
|
|
||||||
import { PostgreSqlDriver, SqlEntityManager } from "@mikro-orm/postgresql"
|
import { PostgreSqlDriver, SqlEntityManager } from "@mikro-orm/postgresql"
|
||||||
|
import { asValue } from "awilix"
|
||||||
import { ContainerRegistrationKeys, MedusaError } from "../../common"
|
import { ContainerRegistrationKeys, MedusaError } from "../../common"
|
||||||
import { loadDatabaseConfig } from "../load-module-database-config"
|
|
||||||
import { mikroOrmCreateConnection } from "../../dal"
|
import { mikroOrmCreateConnection } from "../../dal"
|
||||||
|
import { loadDatabaseConfig } from "../load-module-database-config"
|
||||||
|
|
||||||
export async function mikroOrmConnectionLoader({
|
export async function mikroOrmConnectionLoader({
|
||||||
container,
|
container,
|
||||||
@@ -50,7 +50,8 @@ export async function mikroOrmConnectionLoader({
|
|||||||
let dbConfig
|
let dbConfig
|
||||||
const shouldSwallowError = !!(
|
const shouldSwallowError = !!(
|
||||||
options as ModulesSdkTypes.ModuleServiceInitializeOptions
|
options as ModulesSdkTypes.ModuleServiceInitializeOptions
|
||||||
)?.database.connection
|
)?.database?.connection
|
||||||
|
|
||||||
dbConfig = {
|
dbConfig = {
|
||||||
...loadDatabaseConfig(
|
...loadDatabaseConfig(
|
||||||
"product",
|
"product",
|
||||||
@@ -58,7 +59,7 @@ export async function mikroOrmConnectionLoader({
|
|||||||
shouldSwallowError
|
shouldSwallowError
|
||||||
),
|
),
|
||||||
connection: (options as ModulesSdkTypes.ModuleServiceInitializeOptions)
|
connection: (options as ModulesSdkTypes.ModuleServiceInitializeOptions)
|
||||||
?.database.connection,
|
?.database?.connection,
|
||||||
}
|
}
|
||||||
|
|
||||||
manager ??= await loadDefault({
|
manager ??= await loadDefault({
|
||||||
|
|||||||
Reference in New Issue
Block a user