Fix user email unique constraint (#8898)
## Context Fix wrong unique index on user email as we don't want an index on email/deletedAt but a partial on a where condition on deletedAt. This should enforce email unicity excluding the ones that have a deletedAt ## Test Run ```sql SELECT email, COUNT(*) as duplicate_count FROM core."user" WHERE "deletedAt" IS NULL GROUP BY email HAVING COUNT(*) > 1 ORDER BY duplicate_count DESC; ``` to check duplicates before running the migration
This commit is contained in:
@ -5,11 +5,11 @@ import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
Index,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
Relation,
|
||||
Unique,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
@ -28,7 +28,10 @@ registerEnumType(OnboardingStatus, {
|
||||
|
||||
@Entity({ name: 'user', schema: 'core' })
|
||||
@ObjectType('User')
|
||||
@Unique('UQ_USER_EMAIL', ['email', 'deletedAt'])
|
||||
@Index('UQ_USER_EMAIL', ['email'], {
|
||||
unique: true,
|
||||
where: '"deletedAt" IS NULL',
|
||||
})
|
||||
export class User {
|
||||
@IDField(() => UUIDScalarType)
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
|
||||
Reference in New Issue
Block a user