Spaces:
Sleeping
Sleeping
Unique email phone number in database
Browse files
backend/src/entities/user.entity.ts
CHANGED
@@ -24,20 +24,21 @@ export class UserEntity extends BaseEntity {
|
|
24 |
@Column({ nullable: true })
|
25 |
full_name: string;
|
26 |
|
27 |
-
@Column({ nullable: true })
|
28 |
phone_number: string;
|
29 |
|
|
|
30 |
@Column({ nullable: true })
|
31 |
address: string;
|
32 |
|
33 |
-
@Column({ nullable: true })
|
34 |
email: string;
|
35 |
|
36 |
@IsOptional()
|
37 |
@Column({ nullable: true })
|
38 |
role_id: number;
|
39 |
|
40 |
-
@Column(
|
41 |
hash_password: string;
|
42 |
|
43 |
@IsOptional()
|
|
|
24 |
@Column({ nullable: true })
|
25 |
full_name: string;
|
26 |
|
27 |
+
@Column({ nullable: true, unique: true })
|
28 |
phone_number: string;
|
29 |
|
30 |
+
@IsOptional()
|
31 |
@Column({ nullable: true })
|
32 |
address: string;
|
33 |
|
34 |
+
@Column({ nullable: true, unique: true })
|
35 |
email: string;
|
36 |
|
37 |
@IsOptional()
|
38 |
@Column({ nullable: true })
|
39 |
role_id: number;
|
40 |
|
41 |
+
@Column()
|
42 |
hash_password: string;
|
43 |
|
44 |
@IsOptional()
|
backend/src/migrations/1729846207793-unique-email-phone.ts
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { MigrationInterface, QueryRunner } from "typeorm";
|
2 |
+
|
3 |
+
export class UniqueEmailPhone1729846207793 implements MigrationInterface {
|
4 |
+
name = 'UniqueEmailPhone1729846207793'
|
5 |
+
|
6 |
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
7 |
+
await queryRunner.query(`ALTER TABLE "users" ADD CONSTRAINT "UQ_17d1817f241f10a3dbafb169fd2" UNIQUE ("phone_number")`);
|
8 |
+
await queryRunner.query(`ALTER TABLE "users" ADD CONSTRAINT "UQ_97672ac88f789774dd47f7c8be3" UNIQUE ("email")`);
|
9 |
+
await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "hash_password" SET NOT NULL`);
|
10 |
+
}
|
11 |
+
|
12 |
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
13 |
+
await queryRunner.query(`ALTER TABLE "users" ALTER COLUMN "hash_password" DROP NOT NULL`);
|
14 |
+
await queryRunner.query(`ALTER TABLE "users" DROP CONSTRAINT "UQ_97672ac88f789774dd47f7c8be3"`);
|
15 |
+
await queryRunner.query(`ALTER TABLE "users" DROP CONSTRAINT "UQ_17d1817f241f10a3dbafb169fd2"`);
|
16 |
+
await queryRunner.query(`DROP TABLE "feeds"`);
|
17 |
+
}
|
18 |
+
|
19 |
+
}
|