From 2ee374fafc492be14ecea82a555fd4b29261e838 Mon Sep 17 00:00:00 2001 From: Riqwan Thamir Date: Wed, 28 Aug 2024 10:10:35 +0200 Subject: [PATCH] fix(order): run migration before setting not null (#8831) --- .../order/src/migrations/Migration20240827133639.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/modules/order/src/migrations/Migration20240827133639.ts b/packages/modules/order/src/migrations/Migration20240827133639.ts index 979d56c359..a1587cac1f 100644 --- a/packages/modules/order/src/migrations/Migration20240827133639.ts +++ b/packages/modules/order/src/migrations/Migration20240827133639.ts @@ -3,7 +3,15 @@ import { Migration } from "@mikro-orm/migrations" export class Migration20240827133639 extends Migration { async up(): Promise { this.addSql( - 'alter table if exists "return_item" add column if not exists "damaged_quantity" numeric not null default 0, add column if not exists "raw_damaged_quantity" jsonb not null;' + 'alter table if exists "return_item" add column if not exists "damaged_quantity" numeric not null default 0, add column if not exists "raw_damaged_quantity" jsonb;' + ) + + this.addSql( + `UPDATE "return_item" SET raw_damaged_quantity = '{"value": "0", "precision": 20}'::jsonb;` + ) + + this.addSql( + 'ALTER TABLE IF EXISTS "return_item" ALTER COLUMN "raw_damaged_quantity" SET NOT NULL;' ) }