fix(medusa): Create migration to ensure correct variant inventory column (#3384)

* add migration to ensure quantity is called required quantity

* add changeset
This commit is contained in:
Philip Korsholm
2023-03-08 15:27:43 +01:00
committed by GitHub
parent ce577f2696
commit 9f508c8bd8
3 changed files with 37 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
Fix(medusa): Column naming on migrations

View File

@@ -14,7 +14,7 @@ export class multiLocation1671711415179 implements MigrationInterface {
`CREATE INDEX "IDX_c2203162ca946a71aeb98390b0" ON "sales_channel_location" ("location_id") `
)
await queryRunner.query(
`CREATE TABLE "product_variant_inventory_item" ("id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "inventory_item_id" text NOT NULL, "variant_id" text NOT NULL, "required_quantity" integer NOT NULL DEFAULT '1', CONSTRAINT "UQ_c9be7c1b11a1a729eb51d1b6bca" UNIQUE ("variant_id", "inventory_item_id"), CONSTRAINT "PK_9a1188b8d36f4d198303b4f7efa" PRIMARY KEY ("id"))`
`CREATE TABLE "product_variant_inventory_item" ("id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "inventory_item_id" text NOT NULL, "variant_id" text NOT NULL, "quantity" integer NOT NULL DEFAULT '1', CONSTRAINT "UQ_c9be7c1b11a1a729eb51d1b6bca" UNIQUE ("variant_id", "inventory_item_id"), CONSTRAINT "PK_9a1188b8d36f4d198303b4f7efa" PRIMARY KEY ("id"))`
)
await queryRunner.query(
`CREATE INDEX "IDX_c74e8c2835094a37dead376a3b" ON "product_variant_inventory_item" ("inventory_item_id") `

View File

@@ -0,0 +1,31 @@
import { MigrationInterface, QueryRunner } from "typeorm"
export class ensureRequiredQuantity1678093365811 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DO
$$
BEGIN
ALTER TABLE product_variant_inventory_item
RENAME COLUMN quantity TO required_quantity;
EXCEPTION
WHEN undefined_column THEN
END;
$$;
`)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DO
$$
BEGIN
ALTER TABLE product_variant_inventory_item
RENAME COLUMN required_quantity TO quantity;
EXCEPTION
WHEN undefined_column THEN
END;
$$;
`)
}
}