fix(product): when running migrations, prevent exploding on isolated case (#5643)
* fix(product): when running migrations, prevent exploding on isolated case * chore: remove try catch block * chore: added variant test fixes * chore: update name of var
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/product": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(product): when running migrations, prevent exploding on isolated case
|
||||||
+9
-4
@@ -170,6 +170,8 @@ describe("ProductModuleService products", function () {
|
|||||||
thumbnail: images[0],
|
thumbnail: images[0],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const variantTitle = data.variants[0].title
|
||||||
|
|
||||||
const updateData = {
|
const updateData = {
|
||||||
...data,
|
...data,
|
||||||
id: productOne.id,
|
id: productOne.id,
|
||||||
@@ -191,11 +193,14 @@ describe("ProductModuleService products", function () {
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(product.images).toHaveLength(1)
|
const createdVariant = product.variants.find(
|
||||||
expect(product.variants[0].options).toHaveLength(1)
|
(v) => v.title === variantTitle
|
||||||
expect(product.tags).toHaveLength(1)
|
)
|
||||||
expect(product.variants).toHaveLength(1)
|
|
||||||
|
|
||||||
|
expect(product.images).toHaveLength(1)
|
||||||
|
expect(createdVariant?.options).toHaveLength(1)
|
||||||
|
expect(product.tags).toHaveLength(1)
|
||||||
|
expect(product.variants).toHaveLength(2)
|
||||||
expect(product).toEqual(
|
expect(product).toEqual(
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
|
|||||||
@@ -2,14 +2,6 @@ import { Migration } from "@mikro-orm/migrations"
|
|||||||
|
|
||||||
export class Migration20230719100648 extends Migration {
|
export class Migration20230719100648 extends Migration {
|
||||||
async up(): Promise<void> {
|
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(
|
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"));'
|
'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"));'
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user