|
1
|
import { Migration } from "@medusajs/framework/mikro-orm/migrations" |
|
2
|
|
|
3
|
export class Migration20240703095850 extends Migration { |
|
4
|
async up(): Promise<void> { |
|
5
|
this.addSql('drop index if exists "IDX_user_email";') |
|
6
|
|
|
7
|
this.addSql( |
|
8
|
'CREATE UNIQUE INDEX "IDX_user_email" ON "user" (email) WHERE deleted_at IS NULL;' |
|
9
|
) |
|
10
|
// Adding this log here as the point of failure is not in this function, but bundled up when running all pending migration |
|
11
|
console.info( |
|
12
|
`Note: If the index "IDX_user_email" fails to create, then delete any existing users with duplicate emails before retrying the migration.` |
|
13
|
) |
|
14
|
} |
|
15
|
|
|
16
|
async down(): Promise<void> { |
|
17
|
this.addSql( |
|
18
|
'CREATE INDEX IF NOT EXISTS "IDX_user_email" ON "user" (email) WHERE deleted_at IS NULL;' |
|
19
|
) |
|
20
|
} |
|
21
|
} |