fix: user email is set to a unique index (#7917)
This commit is contained in:
@@ -126,7 +126,7 @@
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_invite_token\" ON \"invite\" (deleted_at) WHERE deleted_at IS NOT NULL"
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_invite_deleted_at\" ON \"invite\" (deleted_at) WHERE deleted_at IS NOT NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "invite_pkey",
|
||||
@@ -241,7 +241,7 @@
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_user_email\" ON \"user\" (email) WHERE deleted_at IS NULL"
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_user_email\" ON \"user\" (email) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_user_deleted_at",
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
|
||||
export class Migration20240703095850 extends Migration {
|
||||
async up(): Promise<void> {
|
||||
this.addSql('drop index if exists "IDX_user_email";')
|
||||
|
||||
this.addSql(
|
||||
'CREATE UNIQUE INDEX "IDX_user_email" ON "user" (email) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
// Adding this log here as the point of failure is not in this function, but bundled up when running all pending migration
|
||||
console.warn(
|
||||
`Note: If the index "IDX_user_email" fails to create, then delete any existing users with duplicate emails before retrying the migration.`
|
||||
)
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_user_email" ON "user" (email) WHERE deleted_at IS NULL;'
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user