|
1
|
import { Migration } from "@medusajs/framework/mikro-orm/migrations" |
|
2
|
|
|
3
|
export class Migration20250212131240 extends Migration { |
|
4
|
override async up(): Promise<void> { |
|
5
|
this.addSql( |
|
6
|
`create table if not exists "credit_line" ("id" text not null, "cart_id" text not null, "reference" text null, "reference_id" text null, "amount" numeric not null, "raw_amount" jsonb not null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "credit_line_pkey" primary key ("id"));` |
|
7
|
) |
|
8
|
|
|
9
|
this.addSql( |
|
10
|
`CREATE INDEX IF NOT EXISTS "IDX_credit_line_cart_id" ON "credit_line" (cart_id) WHERE deleted_at IS NULL;` |
|
11
|
) |
|
12
|
|
|
13
|
this.addSql( |
|
14
|
`CREATE INDEX IF NOT EXISTS "IDX_credit_line_deleted_at" ON "credit_line" (deleted_at) WHERE deleted_at IS NULL;` |
|
15
|
) |
|
16
|
|
|
17
|
this.addSql( |
|
18
|
`CREATE INDEX IF NOT EXISTS "IDX_cart_credit_line_reference_reference_id" ON "credit_line" (reference, reference_id) WHERE deleted_at IS NOT NULL;` |
|
19
|
) |
|
20
|
|
|
21
|
this.addSql( |
|
22
|
`alter table if exists "credit_line" add constraint "credit_line_cart_id_foreign" foreign key ("cart_id") references "cart" ("id") on update cascade;` |
|
23
|
) |
|
24
|
} |
|
25
|
|
|
26
|
override async down(): Promise<void> { |
|
27
|
this.addSql(`drop table if exists "credit_line" cascade;`) |
|
28
|
} |
|
29
|
} |