diff --git a/.changeset/real-icons-complain.md b/.changeset/real-icons-complain.md new file mode 100644 index 0000000000..96184075cb --- /dev/null +++ b/.changeset/real-icons-complain.md @@ -0,0 +1,5 @@ +--- +"@medusajs/product": patch +--- + +fix(product): when running migrations, prevent exploding on isolated case diff --git a/packages/product/integration-tests/__tests__/services/product-module-service/products.spec.ts b/packages/product/integration-tests/__tests__/services/product-module-service/products.spec.ts index 5dc4d51173..abfbb7c579 100644 --- a/packages/product/integration-tests/__tests__/services/product-module-service/products.spec.ts +++ b/packages/product/integration-tests/__tests__/services/product-module-service/products.spec.ts @@ -170,6 +170,8 @@ describe("ProductModuleService products", function () { thumbnail: images[0], }) + const variantTitle = data.variants[0].title + const updateData = { ...data, id: productOne.id, @@ -191,11 +193,14 @@ describe("ProductModuleService products", function () { ], }) - expect(product.images).toHaveLength(1) - expect(product.variants[0].options).toHaveLength(1) - expect(product.tags).toHaveLength(1) - expect(product.variants).toHaveLength(1) + const createdVariant = product.variants.find( + (v) => v.title === variantTitle + ) + expect(product.images).toHaveLength(1) + expect(createdVariant?.options).toHaveLength(1) + expect(product.tags).toHaveLength(1) + expect(product.variants).toHaveLength(2) expect(product).toEqual( expect.objectContaining({ id: expect.any(String), diff --git a/packages/product/src/migrations/Migration20230719100648.ts b/packages/product/src/migrations/Migration20230719100648.ts index 5f46f17f0f..a99311bc5b 100644 --- a/packages/product/src/migrations/Migration20230719100648.ts +++ b/packages/product/src/migrations/Migration20230719100648.ts @@ -2,14 +2,6 @@ import { Migration } from "@mikro-orm/migrations" export class Migration20230719100648 extends Migration { async up(): Promise { - 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"));' )