Skip to content

Commit

Permalink
Merge branch 'develop' into chore/order-dml
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-r-l-rodrigues authored Jan 21, 2025
2 parents f15e15f + cd75806 commit 25f3687
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-fireants-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-medusa-app": patch
---

fix(create-medusa-app): fix database name from input not used in setup
6 changes: 6 additions & 0 deletions .changeset/nervous-carrots-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/medusa": patch
"@medusajs/framework": patch
---

fix(framework): migration scripts regexp
1 change: 1 addition & 0 deletions packages/cli/create-medusa-app/src/utils/create-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export async function getDbClientAndCredentials({
client: pg.Client
dbConnectionString: string
verbose?: boolean
dbName?: string
}> {
if (dbName) {
return await getForDbName({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class MedusaProjectCreator
}

private async setupDatabase(): Promise<void> {
const dbName = `medusa-${slugify(this.projectName)}`
let dbName = `medusa-${slugify(this.projectName)}`
const { client, dbConnectionString, ...rest } =
await getDbClientAndCredentials({
dbName,
Expand All @@ -115,11 +115,12 @@ export class MedusaProjectCreator
this.client = client
this.dbConnectionString = dbConnectionString
this.isDbInitialized = true
dbName = rest.dbName || dbName

if (!this.options.dbUrl) {
this.factBoxOptions.interval = displayFactBox({
...this.factBoxOptions,
title: "Creating database...",
message: "Creating database...",
})

this.client = await runCreateDb({
Expand Down
2 changes: 1 addition & 1 deletion packages/core/framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"watch": "tsc --watch ",
"watch:test": "tsc --watch",
"build": "rimraf dist && tsc --build",
"test": "jest --runInBand --bail --passWithNoTests --forceExit"
"test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts"
},
"devDependencies": {
"@medusajs/cli": "^2.3.1",
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function test() {
console.log("test")
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { MedusaContainer } from "@medusajs/types"
import { MigrationScriptsMigrator } from "../run-migration-scripts"
import { jest } from "@jest/globals"
import path from "path"
import { MedusaContainer } from "@medusajs/types"
import { ContainerRegistrationKeys, Modules } from "@medusajs/utils"
import path from "path"
import { MigrationScriptsMigrator } from "../run-migration-scripts"

const mockPgConnection = {
raw: jest.fn(),
Expand Down Expand Up @@ -171,4 +171,29 @@ describe("MigrationScriptsMigrator", () => {
)
})
})

describe("loadMigrationFiles", () => {
it("should load migration files correctly", async () => {
const result = await migrator.loadMigrationFiles([
path.join(
__dirname,
"..",
"__fixtures__",
"project",
"migration-scripts"
),
])
expect(result).toHaveLength(1)
expect(result[0]).toEqual(
path.join(
__dirname,
"..",
"__fixtures__",
"project",
"migration-scripts",
"test.ts"
)
)
})
})
})
10 changes: 5 additions & 5 deletions packages/core/framework/src/migrations/migrator.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { join } from "path"
import { MedusaContainer } from "@medusajs/types"
import { Knex } from "@mikro-orm/knex"
import { glob } from "glob"
import { join } from "path"
import { logger } from "../logger"
import { MedusaContainer } from "@medusajs/types"
import { ContainerRegistrationKeys } from "../utils"
import { Knex } from "@mikro-orm/knex"

export abstract class Migrator {
protected abstract migration_table_name: string
Expand Down Expand Up @@ -135,9 +135,9 @@ export abstract class Migrator {
}

try {
const scriptFiles = glob.sync("*.{js,(!d.)ts}", {
const scriptFiles = glob.sync("*.{js,ts}", {
cwd: basePath,
ignore: ["**/index.{js,ts}"],
ignore: ["**/index.{js,ts}", "**/*.d.ts"],
})

if (!scriptFiles?.length) {
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/commands/plugin/db/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function getEntitiesForModule(path: string) {
const entities = [] as any[]

const entityPaths = glob.sync(join(path, "models", "*.ts"), {
ignore: ["**/index.{js,ts}"],
ignore: ["**/index.{js,ts}", "**/*.d.ts"],
})

for (const entityPath of entityPaths) {
Expand Down

0 comments on commit 25f3687

Please sign in to comment.