1 import { Migration } from "@medusajs/framework/mikro-orm/migrations"
2 import { ulid } from "ulid"
3
4 export class Migration20250924135437 extends Migration {
5 override async up(): Promise<void> {
6 const [existingReason] = await this.execute(`
7 SELECT 1 as exists
8 FROM "refund_reason"
9 LIMIT 1
10 `)
11
12 if (!existingReason) {
13 // 2. Create default shipping option type
14 await this.execute(`
15 INSERT INTO "refund_reason" (id, label, description)
16 VALUES
17 ('refr_${ulid()}', 'Shipping Issue', 'Refund due to lost, delayed, or misdelivered shipment'),
18 ('refr_${ulid()}', 'Customer Care Adjustment', 'Refund given as goodwill or compensation for inconvenience'),
19 ('refr_${ulid()}', 'Pricing Error', 'Refund to correct an overcharge, missing discount, or incorrect price');
20 `)
21 }
22 }
23
24 override async down(): Promise<void> {
25 // Remove the default refund reasons we created
26 this.addSql(`
27 DELETE FROM "refund_reason"
28 WHERE ("label", "description") IN (
29 ('Shipping Issue', 'Refund due to lost, delayed, or misdelivered shipment'),
30 ('Customer Care Adjustment', 'Refund given as goodwill or compensation for inconvenience'),
31 ('Pricing Error', 'Refund to correct an overcharge, missing discount, or incorrect price')
32 )
33 `)
34 }
35 }