diff --git a/server/libs/database/src/entities/user.entity.ts b/server/libs/database/src/entities/user.entity.ts index 13bfc3d2e0..1d0a659bd9 100644 --- a/server/libs/database/src/entities/user.entity.ts +++ b/server/libs/database/src/entities/user.entity.ts @@ -15,7 +15,7 @@ export class UserEntity { @Column({ default: false }) isAdmin!: boolean; - @Column() + @Column({ unique: true }) email!: string; @Column({ default: '', select: false }) diff --git a/server/libs/database/src/migrations/1670633210032-AddUserEmailUniqueConstraint.ts b/server/libs/database/src/migrations/1670633210032-AddUserEmailUniqueConstraint.ts new file mode 100644 index 0000000000..50a67ae94f --- /dev/null +++ b/server/libs/database/src/migrations/1670633210032-AddUserEmailUniqueConstraint.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddUserEmailUniqueConstraint1670633210032 implements MigrationInterface { + name = 'AddUserEmailUniqueConstraint1670633210032' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "users" ADD CONSTRAINT "UQ_97672ac88f789774dd47f7c8be3" UNIQUE ("email")`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "users" DROP CONSTRAINT "UQ_97672ac88f789774dd47f7c8be3"`); + } + +}