|
1
|
import { Migration } from "@medusajs/framework/mikro-orm/migrations"; |
|
2
|
|
|
3
|
export class Migration20250722080351 extends Migration { |
|
4
|
|
|
5
|
override async up(): Promise<void> { |
|
6
|
this.addSql(`alter table if exists "store_credit_account_transaction" drop constraint if exists "store_credit_account_transaction_transaction_group_id_foreign";`); |
|
7
|
|
|
8
|
this.addSql(`drop table if exists "store_credit_transaction_group" cascade;`); |
|
9
|
|
|
10
|
this.addSql(`alter table if exists "store_credit_account" add column if not exists "code" text null;`); |
|
11
|
|
|
12
|
this.addSql(`drop index if exists "IDX_store_credit_account_transaction_transaction_group_id";`); |
|
13
|
this.addSql(`alter table if exists "store_credit_account_transaction" drop column if exists "transaction_group_id";`); |
|
14
|
} |
|
15
|
|
|
16
|
override async down(): Promise<void> { |
|
17
|
this.addSql(`create table if not exists "store_credit_transaction_group" ("id" text not null, "code" text not null, "account_id" text not null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "store_credit_transaction_group_pkey" primary key ("id"));`); |
|
18
|
this.addSql(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_store_credit_transaction_group_code_unique" ON "store_credit_transaction_group" (code) WHERE deleted_at IS NULL;`); |
|
19
|
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_store_credit_transaction_group_account_id" ON "store_credit_transaction_group" (account_id) WHERE deleted_at IS NULL;`); |
|
20
|
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_store_credit_transaction_group_deleted_at" ON "store_credit_transaction_group" (deleted_at) WHERE deleted_at IS NULL;`); |
|
21
|
this.addSql(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_account_id" ON "store_credit_transaction_group" (code, account_id) WHERE deleted_at IS NULL;`); |
|
22
|
|
|
23
|
this.addSql(`alter table if exists "store_credit_transaction_group" add constraint "store_credit_transaction_group_account_id_foreign" foreign key ("account_id") references "store_credit_account" ("id") on update cascade;`); |
|
24
|
|
|
25
|
this.addSql(`alter table if exists "store_credit_account" drop column if exists "code";`); |
|
26
|
|
|
27
|
this.addSql(`alter table if exists "store_credit_account_transaction" add column if not exists "transaction_group_id" text null;`); |
|
28
|
this.addSql(`alter table if exists "store_credit_account_transaction" add constraint "store_credit_account_transaction_transaction_group_id_foreign" foreign key ("transaction_group_id") references "store_credit_transaction_group" ("id") on update cascade on delete set null;`); |
|
29
|
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_store_credit_account_transaction_transaction_group_id" ON "store_credit_account_transaction" (transaction_group_id) WHERE deleted_at IS NULL;`); |
|
30
|
} |
|
31
|
|
|
32
|
} |