Raw
1 import { Migration } from "@medusajs/framework/mikro-orm/migrations"
2
3 export class Migration20250929124701 extends Migration {
4 override async up(): Promise<void> {
5 // Step 1: Add the column as nullable
6 this.addSql(`alter table "refund_reason" add column "code" text;`)
7
8 // Step 2: Populate the code column from label (convert to snake_case)
9 this.addSql(`
10 update "refund_reason"
11 set "code" = lower(replace("label", ' ', '_'));
12 `)
13
14 // Step 3: Set the column to not nullable
15 this.addSql(`alter table "refund_reason" alter column "code" set not null;`)
16 }
17
18 override async down(): Promise<void> {
19 // Remove the code column
20 this.addSql(`alter table "refund_reason" drop column "code";`)
21 }
22 }