Skip to content

Commit

Permalink
refactor(database): change relation
Browse files Browse the repository at this point in the history
  • Loading branch information
Shchepotin committed May 6, 2024
1 parent d638791 commit 8c1df7a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class CreateUser1709769642152 implements MigrationInterface {
name = 'CreateUser1709769642152';
export class CreateUser1715028537217 implements MigrationInterface {
name = 'CreateUser1715028537217';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "status" ("id" integer NOT NULL, "name" character varying NOT NULL, CONSTRAINT "PK_e12743a7086ec826733f54e1d95" PRIMARY KEY ("id"))`,
`CREATE TABLE "role" ("id" integer NOT NULL, "name" character varying NOT NULL, CONSTRAINT "PK_b36bcfe02fc8de3c57a8b2391c2" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE TABLE "role" ("id" integer NOT NULL, "name" character varying NOT NULL, CONSTRAINT "PK_b36bcfe02fc8de3c57a8b2391c2" PRIMARY KEY ("id"))`,
`CREATE TABLE "status" ("id" integer NOT NULL, "name" character varying NOT NULL, CONSTRAINT "PK_e12743a7086ec826733f54e1d95" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE TABLE "file" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "path" character varying NOT NULL, CONSTRAINT "PK_36b46d232307066b3a2c9ea3a1d" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE TABLE "user" ("id" SERIAL NOT NULL, "email" character varying, "password" character varying, "provider" character varying NOT NULL DEFAULT 'email', "socialId" character varying, "firstName" character varying, "lastName" character varying, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP, "photoId" uuid, "roleId" integer, "statusId" integer, CONSTRAINT "UQ_e12875dfb3b1d92d7d7c5377e22" UNIQUE ("email"), CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id"))`,
`CREATE TABLE "user" ("id" SERIAL NOT NULL, "email" character varying, "password" character varying, "provider" character varying NOT NULL DEFAULT 'email', "socialId" character varying, "firstName" character varying, "lastName" character varying, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP NOT NULL DEFAULT now(), "deletedAt" TIMESTAMP, "photoId" uuid, "roleId" integer, "statusId" integer, CONSTRAINT "UQ_e12875dfb3b1d92d7d7c5377e22" UNIQUE ("email"), CONSTRAINT "REL_75e2be4ce11d447ef43be0e374" UNIQUE ("photoId"), CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE INDEX "IDX_9bd2fe7a8e694dedc4ec2f666f" ON "user" ("socialId") `,
Expand Down Expand Up @@ -73,7 +73,7 @@ export class CreateUser1709769642152 implements MigrationInterface {
);
await queryRunner.query(`DROP TABLE "user"`);
await queryRunner.query(`DROP TABLE "file"`);
await queryRunner.query(`DROP TABLE "role"`);
await queryRunner.query(`DROP TABLE "status"`);
await queryRunner.query(`DROP TABLE "role"`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
ManyToOne,
PrimaryGeneratedColumn,
UpdateDateColumn,
JoinColumn,
OneToOne,
} from 'typeorm';
import { RoleEntity } from '../../../../../roles/infrastructure/persistence/relational/entities/role.entity';
import { StatusEntity } from '../../../../../statuses/infrastructure/persistence/relational/entities/status.entity';
Expand Down Expand Up @@ -90,9 +92,10 @@ export class UserEntity extends EntityRelationalHelper {
@ApiResponseProperty({
type: () => FileEntity,
})
@ManyToOne(() => FileEntity, {
@OneToOne(() => FileEntity, {
eager: true,
})
@JoinColumn()
photo?: FileEntity | null;

@ApiResponseProperty({
Expand Down

0 comments on commit 8c1df7a

Please sign in to comment.