1 import { Migration } from "@mikro-orm/migrations"
2
3 export class Migration20251113183352 extends Migration {
4 override async up(): Promise<void> {
5 // Populate product_product_option_value with all existing implicit relationships
6 // For each product-option link, create links to all values of that option
7 this.addSql(`
8 insert into "product_product_option_value" ("id", "product_product_option_id", "product_option_value_id")
9 select
10 gen_random_uuid(),
11 ppo.id,
12 pov.id
13 from "product_product_option" ppo
14 inner join "product_option_value" pov on pov.option_id = ppo.product_option_id
15 where ppo.deleted_at is null and pov.deleted_at is null;
16 `)
17 }
18
19 override async down(): Promise<void> {
20 // Remove all the records that were created by the up migration
21 // This is a destructive operation and will remove the granular relationships
22 this.addSql(`
23 delete from "product_product_option_value"
24 where "product_product_option_id" in (
25 select id from "product_product_option" where deleted_at is null
26 );
27 `)
28 }
29 }