fix(framework): Exclude .d.ts files from the glob search and fix insert query (#10990)
**What** - Exclude definition file from the glob search string - Properly generate the insert query string
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/framework": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(framework): Exclude .d.ts files from the glob search and Properly generate the insert query string
|
||||||
@@ -44,9 +44,6 @@ describe("MigrationScriptsMigrator", () => {
|
|||||||
jest
|
jest
|
||||||
.spyOn(migrator as any, "getPendingMigrations")
|
.spyOn(migrator as any, "getPendingMigrations")
|
||||||
.mockResolvedValue([scriptPath])
|
.mockResolvedValue([scriptPath])
|
||||||
jest
|
|
||||||
.spyOn(migrator as any, "insertMigration")
|
|
||||||
.mockResolvedValue(undefined)
|
|
||||||
jest
|
jest
|
||||||
.spyOn(migrator as any, "trackDuration")
|
.spyOn(migrator as any, "trackDuration")
|
||||||
.mockReturnValue({ getSeconds: () => 1 })
|
.mockReturnValue({ getSeconds: () => 1 })
|
||||||
@@ -63,13 +60,18 @@ describe("MigrationScriptsMigrator", () => {
|
|||||||
|
|
||||||
expect(mockScript).toHaveBeenCalled()
|
expect(mockScript).toHaveBeenCalled()
|
||||||
|
|
||||||
expect(mockPgConnection.raw).toHaveBeenCalledWith(
|
expect(mockPgConnection.raw).toHaveBeenNthCalledWith(
|
||||||
|
1,
|
||||||
|
expect.stringContaining(
|
||||||
|
"INSERT INTO script_migrations (script_name) VALUES (?)"
|
||||||
|
),
|
||||||
|
[path.basename(scriptPath)]
|
||||||
|
)
|
||||||
|
expect(mockPgConnection.raw).toHaveBeenNthCalledWith(
|
||||||
|
2,
|
||||||
expect.stringContaining("UPDATE script_migrations"),
|
expect.stringContaining("UPDATE script_migrations"),
|
||||||
[path.basename(scriptPath)]
|
[path.basename(scriptPath)]
|
||||||
)
|
)
|
||||||
expect(migrator["insertMigration"]).toHaveBeenCalledWith([
|
|
||||||
{ script_name: `'${path.basename(scriptPath)}'` },
|
|
||||||
])
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should handle failed migrations by cleaning up", async () => {
|
it("should handle failed migrations by cleaning up", async () => {
|
||||||
|
|||||||
@@ -97,8 +97,13 @@ export abstract class Migrator {
|
|||||||
await this.pgConnection.raw(
|
await this.pgConnection.raw(
|
||||||
`INSERT INTO ${this.migration_table_name} (${columns.join(
|
`INSERT INTO ${this.migration_table_name} (${columns.join(
|
||||||
", "
|
", "
|
||||||
)}) VALUES (${new Array(values.length).fill("?").join(",")})`,
|
)}) VALUES ${values
|
||||||
values
|
.map(
|
||||||
|
(itemValues) =>
|
||||||
|
`(${new Array(itemValues.length).fill("?").join(",")})`
|
||||||
|
)
|
||||||
|
.join(",")}`,
|
||||||
|
values.flat()
|
||||||
)
|
)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(
|
logger.error(
|
||||||
@@ -130,7 +135,7 @@ export abstract class Migrator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const scriptFiles = glob.sync("*.{js,ts}", {
|
const scriptFiles = glob.sync("*.{js,(!d.)ts}", {
|
||||||
cwd: basePath,
|
cwd: basePath,
|
||||||
ignore: ["**/index.{js,ts}"],
|
ignore: ["**/index.{js,ts}"],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export class MigrationScriptsMigrator extends Migrator {
|
|||||||
const scriptName = basename(script)
|
const scriptName = basename(script)
|
||||||
|
|
||||||
const err = await this.insertMigration([
|
const err = await this.insertMigration([
|
||||||
{ script_name: `'${scriptName}'` },
|
{ script_name: scriptName },
|
||||||
]).catch((e) => e)
|
]).catch((e) => e)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,7 +99,7 @@ export class MigrationScriptsMigrator extends Migrator {
|
|||||||
|
|
||||||
#updateMigrationFinishedAt(scriptName: string) {
|
#updateMigrationFinishedAt(scriptName: string) {
|
||||||
return this.pgConnection.raw(
|
return this.pgConnection.raw(
|
||||||
`UPDATE ${this.migration_table_name} SET finished_at = CURRENT_TIMESTAMP WHERE script_name = ?`,
|
`UPDATE ${this.migration_table_name} SET finished_at = NOW() WHERE script_name = ?`,
|
||||||
[scriptName]
|
[scriptName]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user