1 import { Migration } from "@medusajs/framework/mikro-orm/migrations";
2
3 export class Migration20260301002050 extends Migration {
4
5 override async up(): Promise<void> {
6 this.addSql(`alter table if exists "product" drop column if exists "raw_weight", drop column if exists "raw_length", drop column if exists "raw_height", drop column if exists "raw_width";`);
7
8 this.addSql(`alter table if exists "product" alter column "weight" type real using ("weight"::real);`);
9 this.addSql(`alter table if exists "product" alter column "length" type real using ("length"::real);`);
10 this.addSql(`alter table if exists "product" alter column "height" type real using ("height"::real);`);
11 this.addSql(`alter table if exists "product" alter column "width" type real using ("width"::real);`);
12
13 this.addSql(`alter table if exists "product_variant" drop column if exists "raw_weight", drop column if exists "raw_length", drop column if exists "raw_height", drop column if exists "raw_width";`);
14
15 this.addSql(`alter table if exists "product_variant" alter column "weight" type real using ("weight"::real);`);
16 this.addSql(`alter table if exists "product_variant" alter column "length" type real using ("length"::real);`);
17 this.addSql(`alter table if exists "product_variant" alter column "height" type real using ("height"::real);`);
18 this.addSql(`alter table if exists "product_variant" alter column "width" type real using ("width"::real);`);
19 }
20
21 override async down(): Promise<void> {
22 this.addSql(`alter table if exists "product" add column if not exists "raw_weight" jsonb null, add column if not exists "raw_length" jsonb null, add column if not exists "raw_height" jsonb null, add column if not exists "raw_width" jsonb null;`);
23 this.addSql(`alter table if exists "product" alter column "weight" type numeric using ("weight"::numeric);`);
24 this.addSql(`alter table if exists "product" alter column "length" type numeric using ("length"::numeric);`);
25 this.addSql(`alter table if exists "product" alter column "height" type numeric using ("height"::numeric);`);
26 this.addSql(`alter table if exists "product" alter column "width" type numeric using ("width"::numeric);`);
27
28 this.addSql(`alter table if exists "product_variant" add column if not exists "raw_weight" jsonb null, add column if not exists "raw_length" jsonb null, add column if not exists "raw_height" jsonb null, add column if not exists "raw_width" jsonb null;`);
29 this.addSql(`alter table if exists "product_variant" alter column "weight" type numeric using ("weight"::numeric);`);
30 this.addSql(`alter table if exists "product_variant" alter column "length" type numeric using ("length"::numeric);`);
31 this.addSql(`alter table if exists "product_variant" alter column "height" type numeric using ("height"::numeric);`);
32 this.addSql(`alter table if exists "product_variant" alter column "width" type numeric using ("width"::numeric);`);
33 }
34
35 }