fix(product): Update images before adding not null constraint (#10248)

This commit is contained in:
Oli Juhl
2024-11-25 09:39:43 +01:00
committed by GitHub
parent 1659c9be5d
commit 29ce10b09e

View File

@@ -3,7 +3,7 @@ import { Migration } from '@mikro-orm/migrations';
export class Migration20241122120331 extends Migration {
async up(): Promise<void> {
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;');
}