1 import { Migration } from "@medusajs/framework/mikro-orm/migrations"
2
3 export class Migration20240806072619 extends Migration {
4 async up(): Promise<void> {
5 this.addSql(
6 'create table if not exists "refund_reason" ("id" text not null, "label" text not null, "description" text null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "refund_reason_pkey" primary key ("id"));'
7 )
8
9 this.addSql(
10 'alter table if exists "payment_session" drop constraint if exists "payment_session_status_check";'
11 )
12
13 this.addSql(
14 'alter table if exists "payment_session" drop constraint if exists "payment_session_payment_collection_id_foreign";'
15 )
16
17 this.addSql(
18 'alter table if exists "payment_session" alter column "status" type text using ("status"::text);'
19 )
20 this.addSql(
21 "alter table if exists \"payment_session\" add constraint \"payment_session_status_check\" check (\"status\" in ('authorized', 'captured', 'pending', 'requires_more', 'error', 'canceled'));"
22 )
23 this.addSql(
24 'create index if not exists "IDX_payment_session_deleted_at" on "payment_session" ("deleted_at");'
25 )
26
27 this.addSql('drop index if exists "IDX_capture_deleted_at";')
28 this.addSql('drop index if exists "IDX_refund_deleted_at";')
29 this.addSql(
30 'create index if not exists "IDX_payment_payment_session_id" on "payment" ("payment_session_id");'
31 )
32 this.addSql(
33 'alter table if exists "payment" add constraint "payment_payment_session_id_unique" unique ("payment_session_id");'
34 )
35
36 this.addSql(
37 'create index if not exists "IDX_capture_deleted_at" on "capture" ("deleted_at");'
38 )
39
40 this.addSql(
41 'alter table if exists "refund" add column if not exists "refund_reason_id" text null, add column if not exists "note" text null;'
42 )
43 this.addSql(
44 'create index if not exists "IDX_refund_deleted_at" on "refund" ("deleted_at");'
45 )
46 }
47
48 async down(): Promise<void> {
49 this.addSql('drop table if exists "refund_reason" cascade;')
50
51 this.addSql(
52 'alter table if exists "payment_session" drop constraint if exists "payment_session_status_check";'
53 )
54
55 this.addSql('drop index if exists "IDX_capture_deleted_at";')
56
57 this.addSql('drop index if exists "IDX_payment_payment_session_id";')
58 this.addSql(
59 'alter table if exists "payment" drop constraint if exists "payment_payment_session_id_unique";'
60 )
61 this.addSql(
62 'create index if not exists "IDX_capture_deleted_at" on "payment" ("deleted_at");'
63 )
64 this.addSql(
65 'create index if not exists "IDX_refund_deleted_at" on "payment" ("deleted_at");'
66 )
67
68 this.addSql(
69 'alter table if exists "payment_session" alter column "status" type text using ("status"::text);'
70 )
71 this.addSql(
72 "alter table if exists \"payment_session\" add constraint \"payment_session_status_check\" check (\"status\" in ('authorized', 'pending', 'requires_more', 'error', 'canceled'));"
73 )
74 this.addSql('drop index if exists "IDX_payment_session_deleted_at";')
75 this.addSql('drop index if exists "IDX_refund_deleted_at";')
76 this.addSql(
77 'alter table if exists "refund" drop column if exists "refund_reason_id";'
78 )
79 this.addSql('alter table if exists "refund" drop column if exists "note";')
80 }
81 }