Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(product): when running migrations, prevent exploding on isolated case #5643

Merged
merged 8 commits into from
Nov 20, 2023
5 changes: 5 additions & 0 deletions .changeset/real-icons-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/product": patch
---

fix(product): when running migrations, prevent exploding on isolated case
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ describe("ProductModuleService products", function () {
thumbnail: images[0],
})

const variantTitle = data.variants[0].title

const updateData = {
...data,
id: productOne.id,
Expand All @@ -191,11 +193,14 @@ describe("ProductModuleService products", function () {
],
})

const createdVariant = product.variants.find(
(v) => v.title === variantTitle
)

expect(product.images).toHaveLength(1)
expect(product.variants[0].options).toHaveLength(1)
expect(createdVariant?.options).toHaveLength(1)
expect(product.tags).toHaveLength(1)
expect(product.variants).toHaveLength(1)

expect(product.variants).toHaveLength(2)
expect(product).toEqual(
expect.objectContaining({
id: expect.any(String),
Expand Down
8 changes: 0 additions & 8 deletions packages/product/src/migrations/Migration20230719100648.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ import { Migration } from "@mikro-orm/migrations"

export class Migration20230719100648 extends Migration {
async up(): Promise<void> {
try {
// Prevent from crashing if for some reason the migration is re run (example, typeorm and mikro orm does not have the same migration table)
await this.execute('SELECT 1 FROM "product" LIMIT 1;')
return
} catch {
// noop
}

this.addSql(
'create table IF NOT EXISTS "product_category" ("id" text not null, "name" text not null, "description" text not null default \'\', "handle" text not null, "mpath" text not null, "is_active" boolean not null default false, "is_internal" boolean not null default false, "rank" numeric not null default 0, "parent_category_id" text null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "product_category_pkey" primary key ("id"));'
)
Expand Down