chore(): Generate migrations with correct mikro orm import path (#13893)
* chore(): Generate migrations with correct mikro orm import path * Create shy-melons-jog.md
This commit is contained in:
1 parent
0f79f22ebc
commit
6d7ba778f5
3 files changed
+52
-6
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/utils": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
chore(): Generate migrations with correct mikro orm import path
|
||||||
@@ -14,6 +14,22 @@ import { dirname, join } from "path"
|
|||||||
import { readDir } from "../common"
|
import { readDir } from "../common"
|
||||||
import { CustomDBMigrator } from "../dal/mikro-orm/custom-db-migrator"
|
import { CustomDBMigrator } from "../dal/mikro-orm/custom-db-migrator"
|
||||||
|
|
||||||
|
// Define the replacement mappings
|
||||||
|
const replacements = [
|
||||||
|
// MikroORM imports - replace mikro-orm/{subpath} with @medusajs/framework/mikro-orm/{subpath}
|
||||||
|
{
|
||||||
|
pattern: /from\s+['"]@?mikro-orm\/([^'"]+)['"]/g,
|
||||||
|
// eslint-disable-next-line quotes
|
||||||
|
replacement: 'from "@medusajs/framework/mikro-orm/$1"',
|
||||||
|
},
|
||||||
|
// PG imports - replace pg with @medusajs/framework/pg
|
||||||
|
{
|
||||||
|
pattern: /from\s+['"]pg['"]/g,
|
||||||
|
// eslint-disable-next-line quotes
|
||||||
|
replacement: 'from "@medusajs/framework/pg"',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Events emitted by the migrations class
|
* Events emitted by the migrations class
|
||||||
*/
|
*/
|
||||||
@@ -70,7 +86,33 @@ export class Migrations extends EventEmitter<MigrationsEvents> {
|
|||||||
try {
|
try {
|
||||||
await this.migrateSnapshotFile(migrator["snapshotPath"])
|
await this.migrateSnapshotFile(migrator["snapshotPath"])
|
||||||
await this.ensureSnapshot(migrator["snapshotPath"])
|
await this.ensureSnapshot(migrator["snapshotPath"])
|
||||||
return await migrator.createMigration()
|
const migrationResult = await migrator.createMigration()
|
||||||
|
const code = migrationResult.code
|
||||||
|
if (code) {
|
||||||
|
let modifiedContent = code
|
||||||
|
let wasModified = false
|
||||||
|
|
||||||
|
replacements.forEach(({ pattern, replacement }) => {
|
||||||
|
const newContent = modifiedContent.replace(pattern, replacement)
|
||||||
|
if (newContent !== modifiedContent) {
|
||||||
|
wasModified = true
|
||||||
|
modifiedContent = newContent
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (wasModified) {
|
||||||
|
await writeFile(
|
||||||
|
join(
|
||||||
|
connection.config.getDriver().config.get("migrations").path ?? "",
|
||||||
|
migrationResult.fileName
|
||||||
|
),
|
||||||
|
modifiedContent,
|
||||||
|
"utf-8"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
migrationResult.code = modifiedContent
|
||||||
|
}
|
||||||
|
return migrationResult
|
||||||
} finally {
|
} finally {
|
||||||
await connection.close(true)
|
await connection.close(true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,13 +26,12 @@ export function buildGenerateMigrationScript({
|
|||||||
* @param logger
|
* @param logger
|
||||||
* @param moduleDeclaration
|
* @param moduleDeclaration
|
||||||
*/
|
*/
|
||||||
return async function ({
|
return async function (
|
||||||
options,
|
{ options, logger } = {} as Pick<
|
||||||
logger,
|
|
||||||
}: Pick<
|
|
||||||
LoaderOptions<ModulesSdkTypes.ModuleServiceInitializeOptions>,
|
LoaderOptions<ModulesSdkTypes.ModuleServiceInitializeOptions>,
|
||||||
"options" | "logger"
|
"options" | "logger"
|
||||||
> = {}) {
|
>
|
||||||
|
) {
|
||||||
logger ??= console as unknown as Logger
|
logger ??= console as unknown as Logger
|
||||||
|
|
||||||
logger.info(new Array(TERMINAL_SIZE).join("-"))
|
logger.info(new Array(TERMINAL_SIZE).join("-"))
|
||||||
|
|||||||
Reference in new issue
Block a user