|
1
|
import { Migration } from "@medusajs/framework/mikro-orm/migrations"; |
|
2
|
|
|
3
|
export class Migration20260514083900 extends Migration { |
|
4
|
|
|
5
|
override async up(): Promise<void> { |
|
6
|
this.addSql(`create table if not exists "auth_mfa_factor" ("id" text not null, "auth_identity_id" text not null, "provider" text not null, "status" text not null, "provider_metadata" jsonb null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "auth_mfa_factor_pkey" primary key ("id"));`); |
|
7
|
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_auth_mfa_factor_auth_identity_id" ON "auth_mfa_factor" ("auth_identity_id") WHERE deleted_at IS NULL;`); |
|
8
|
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_auth_mfa_factor_deleted_at" ON "auth_mfa_factor" ("deleted_at") WHERE deleted_at IS NULL;`); |
|
9
|
this.addSql(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_auth_mfa_factor_auth_identity_provider_active" ON "auth_mfa_factor" ("auth_identity_id", "provider") WHERE deleted_at IS NULL AND status IN ('pending', 'enabled');`); |
|
10
|
|
|
11
|
this.addSql(`create table if not exists "auth_mfa_recovery_code" ("id" text not null, "auth_identity_id" text not null, "code_hash" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "auth_mfa_recovery_code_pkey" primary key ("id"));`); |
|
12
|
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_auth_mfa_recovery_code_auth_identity_id" ON "auth_mfa_recovery_code" ("auth_identity_id") WHERE deleted_at IS NULL;`); |
|
13
|
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_auth_mfa_recovery_code_deleted_at" ON "auth_mfa_recovery_code" ("deleted_at") WHERE deleted_at IS NULL;`); |
|
14
|
this.addSql(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_auth_mfa_recovery_code_auth_identity_code_hash" ON "auth_mfa_recovery_code" ("auth_identity_id", "code_hash") WHERE deleted_at IS NULL;`); |
|
15
|
|
|
16
|
this.addSql(`alter table if exists "auth_mfa_factor" add constraint "auth_mfa_factor_auth_identity_id_foreign" foreign key ("auth_identity_id") references "auth_identity" ("id") on update cascade on delete cascade;`); |
|
17
|
|
|
18
|
this.addSql(`alter table if exists "auth_mfa_recovery_code" add constraint "auth_mfa_recovery_code_auth_identity_id_foreign" foreign key ("auth_identity_id") references "auth_identity" ("id") on update cascade on delete cascade;`); |
|
19
|
} |
|
20
|
|
|
21
|
override async down(): Promise<void> { |
|
22
|
this.addSql(`drop table if exists "auth_mfa_factor" cascade;`); |
|
23
|
|
|
24
|
this.addSql(`drop table if exists "auth_mfa_recovery_code" cascade;`); |
|
25
|
} |
|
26
|
|
|
27
|
} |