Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix user email unique constraint #8898

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class FixUserEmailUniqueConstraint1733408604468
implements MigrationInterface
{
name = 'FixUserEmailUniqueConstraint1733408604468';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "core"."user" DROP CONSTRAINT "UQ_USER_EMAIL"`,
);
await queryRunner.query(
`CREATE UNIQUE INDEX "UQ_USER_EMAIL" ON "core"."user" ("email") WHERE "deletedAt" IS NULL`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "core"."UQ_USER_EMAIL"`);
await queryRunner.query(
`ALTER TABLE "core"."user" ADD CONSTRAINT "UQ_USER_EMAIL" UNIQUE ("email", "deletedAt")`,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {
Column,
CreateDateColumn,
Entity,
Index,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
Relation,
Unique,
UpdateDateColumn,
} from 'typeorm';

Expand All @@ -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')
Expand Down
Loading