diff --git a/.changeset/spicy-hornets-know.md b/.changeset/spicy-hornets-know.md new file mode 100644 index 0000000000..f74ba48ba0 --- /dev/null +++ b/.changeset/spicy-hornets-know.md @@ -0,0 +1,5 @@ +--- +"@medusajs/medusa": patch +--- + +Fix(medusa): Column naming on migrations diff --git a/packages/medusa/src/migrations/1671711415179-multi_location.ts b/packages/medusa/src/migrations/1671711415179-multi_location.ts index 8f1d9e4464..7531c8fd1e 100644 --- a/packages/medusa/src/migrations/1671711415179-multi_location.ts +++ b/packages/medusa/src/migrations/1671711415179-multi_location.ts @@ -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") ` diff --git a/packages/medusa/src/migrations/1678093365811-ensure_required_quantity.ts b/packages/medusa/src/migrations/1678093365811-ensure_required_quantity.ts new file mode 100644 index 0000000000..b07fca4b3d --- /dev/null +++ b/packages/medusa/src/migrations/1678093365811-ensure_required_quantity.ts @@ -0,0 +1,31 @@ +import { MigrationInterface, QueryRunner } from "typeorm" + +export class ensureRequiredQuantity1678093365811 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + 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 { + await queryRunner.query(` + DO + $$ + BEGIN + ALTER TABLE product_variant_inventory_item + RENAME COLUMN required_quantity TO quantity; + EXCEPTION + WHEN undefined_column THEN + END; + $$; + `) + } +}