From 29ce10b09e50efce20feb3621b1a23f385cc56e0 Mon Sep 17 00:00:00 2001 From: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> Date: Mon, 25 Nov 2024 09:39:43 +0100 Subject: [PATCH] fix(product): Update images before adding not null constraint (#10248) --- .../modules/product/src/migrations/Migration20241122120331.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/modules/product/src/migrations/Migration20241122120331.ts b/packages/modules/product/src/migrations/Migration20241122120331.ts index efcb5443f0..d8585ef729 100644 --- a/packages/modules/product/src/migrations/Migration20241122120331.ts +++ b/packages/modules/product/src/migrations/Migration20241122120331.ts @@ -3,7 +3,7 @@ import { Migration } from '@mikro-orm/migrations'; export class Migration20241122120331 extends Migration { async up(): Promise { - this.addSql('alter table if exists "image" add column if not exists "rank" integer not null default 0, add column if not exists "product_id" text not null;'); + this.addSql('alter table if exists "image" add column if not exists "rank" integer not null default 0, add column if not exists "product_id" text null;'); // Migrate existing relationships this.addSql(` @@ -19,6 +19,7 @@ export class Migration20241122120331 extends Migration { where pi.image_id = i.id; `); + this.addSql('alter table if exists "image" alter column "product_id" set not null;'); this.addSql('alter table if exists "image" add constraint "image_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;'); this.addSql('drop table if exists "product_images" cascade;'); }