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:
committed by
GitHub
parent
b79dc40bc9
commit
9a742911fe
5
.changeset/tall-gorillas-smash.md
Normal file
5
.changeset/tall-gorillas-smash.md
Normal file
@@ -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
|
||||
.spyOn(migrator as any, "getPendingMigrations")
|
||||
.mockResolvedValue([scriptPath])
|
||||
jest
|
||||
.spyOn(migrator as any, "insertMigration")
|
||||
.mockResolvedValue(undefined)
|
||||
jest
|
||||
.spyOn(migrator as any, "trackDuration")
|
||||
.mockReturnValue({ getSeconds: () => 1 })
|
||||
@@ -63,13 +60,18 @@ describe("MigrationScriptsMigrator", () => {
|
||||
|
||||
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"),
|
||||
[path.basename(scriptPath)]
|
||||
)
|
||||
expect(migrator["insertMigration"]).toHaveBeenCalledWith([
|
||||
{ script_name: `'${path.basename(scriptPath)}'` },
|
||||
])
|
||||
})
|
||||
|
||||
it("should handle failed migrations by cleaning up", async () => {
|
||||
|
||||
@@ -97,8 +97,13 @@ export abstract class Migrator {
|
||||
await this.pgConnection.raw(
|
||||
`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) {
|
||||
logger.error(
|
||||
@@ -130,7 +135,7 @@ export abstract class Migrator {
|
||||
}
|
||||
|
||||
try {
|
||||
const scriptFiles = glob.sync("*.{js,ts}", {
|
||||
const scriptFiles = glob.sync("*.{js,(!d.)ts}", {
|
||||
cwd: basePath,
|
||||
ignore: ["**/index.{js,ts}"],
|
||||
})
|
||||
|
||||
@@ -37,7 +37,7 @@ export class MigrationScriptsMigrator extends Migrator {
|
||||
const scriptName = basename(script)
|
||||
|
||||
const err = await this.insertMigration([
|
||||
{ script_name: `'${scriptName}'` },
|
||||
{ script_name: scriptName },
|
||||
]).catch((e) => e)
|
||||
|
||||
/**
|
||||
@@ -99,7 +99,7 @@ export class MigrationScriptsMigrator extends Migrator {
|
||||
|
||||
#updateMigrationFinishedAt(scriptName: string) {
|
||||
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]
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user