fix(utils,product): mikro orm connection loader (#4825)
Fix shared connection property check
This commit is contained in:
committed by
GitHub
parent
edf9ed4e59
commit
c53fa6cd3b
6
.changeset/tiny-tomatoes-cheer.md
Normal file
6
.changeset/tiny-tomatoes-cheer.md
Normal file
@@ -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,
|
||||
ModulesSdkTypes,
|
||||
} from "@medusajs/types"
|
||||
import { asValue } from "awilix"
|
||||
import { PostgreSqlDriver, SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { asValue } from "awilix"
|
||||
import { ContainerRegistrationKeys, MedusaError } from "../../common"
|
||||
import { loadDatabaseConfig } from "../load-module-database-config"
|
||||
import { mikroOrmCreateConnection } from "../../dal"
|
||||
import { loadDatabaseConfig } from "../load-module-database-config"
|
||||
|
||||
export async function mikroOrmConnectionLoader({
|
||||
container,
|
||||
@@ -50,7 +50,8 @@ export async function mikroOrmConnectionLoader({
|
||||
let dbConfig
|
||||
const shouldSwallowError = !!(
|
||||
options as ModulesSdkTypes.ModuleServiceInitializeOptions
|
||||
)?.database.connection
|
||||
)?.database?.connection
|
||||
|
||||
dbConfig = {
|
||||
...loadDatabaseConfig(
|
||||
"product",
|
||||
@@ -58,7 +59,7 @@ export async function mikroOrmConnectionLoader({
|
||||
shouldSwallowError
|
||||
),
|
||||
connection: (options as ModulesSdkTypes.ModuleServiceInitializeOptions)
|
||||
?.database.connection,
|
||||
?.database?.connection,
|
||||
}
|
||||
|
||||
manager ??= await loadDefault({
|
||||
|
||||
Reference in New Issue
Block a user