Skip to content

Commit a373ddc

Browse files
Johan BookJohan Book
Johan Book
authored and
Johan Book
committed
chore(api): add missing migration
1 parent 9d4a8af commit a373ddc

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

services/api/src/features/chat/infrastructure/entities/chat-conversation.entity.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { Column, Entity, ManyToOne, OneToMany, OneToOne } from "typeorm";
1+
import {
2+
Column,
3+
Entity,
4+
JoinColumn,
5+
ManyToOne,
6+
OneToMany,
7+
OneToOne,
8+
} from "typeorm";
29

310
import { BaseEntity } from "src/core/database";
411
import { Organization } from "src/core/organizations";
@@ -29,8 +36,9 @@ export class ChatConversation extends BaseEntity {
2936
organizationId!: number;
3037

3138
@OneToOne(() => ChatConversationPhoto, (photo) => photo.conversation)
39+
@JoinColumn()
3240
photo?: ChatConversationPhoto;
3341

3442
@Column()
35-
photoId!: string;
43+
photoId?: string;
3644
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm";
2+
3+
export class AddConversationPhotoId1720204937997 implements MigrationInterface {
4+
name = 'AddConversationPhotoId1720204937997'
5+
6+
public async up(queryRunner: QueryRunner): Promise<void> {
7+
await queryRunner.query(`ALTER TABLE "chat_message" DROP CONSTRAINT "FK_a2be22c99b34156574f4e02d0a0"`);
8+
await queryRunner.query(`ALTER TABLE "chat_conversation_photo" ADD "conversationId" character varying NOT NULL`);
9+
await queryRunner.query(`ALTER TABLE "chat_conversation" ADD "photoId" character varying`);
10+
await queryRunner.query(`ALTER TABLE "chat_message" ADD CONSTRAINT "FK_a2be22c99b34156574f4e02d0a0" FOREIGN KEY ("senderId") REFERENCES "profile"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
11+
}
12+
13+
public async down(queryRunner: QueryRunner): Promise<void> {
14+
await queryRunner.query(`ALTER TABLE "chat_message" DROP CONSTRAINT "FK_a2be22c99b34156574f4e02d0a0"`);
15+
await queryRunner.query(`ALTER TABLE "chat_conversation" DROP COLUMN "photoId"`);
16+
await queryRunner.query(`ALTER TABLE "chat_conversation_photo" DROP COLUMN "conversationId"`);
17+
await queryRunner.query(`ALTER TABLE "chat_message" ADD CONSTRAINT "FK_a2be22c99b34156574f4e02d0a0" FOREIGN KEY ("senderId") REFERENCES "profile"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
18+
}
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm";
2+
3+
export class AddMissingColumn1720206668562 implements MigrationInterface {
4+
name = 'AddMissingColumn1720206668562'
5+
6+
public async up(queryRunner: QueryRunner): Promise<void> {
7+
await queryRunner.query(`ALTER TABLE "chat_conversation" DROP COLUMN "photoId"`);
8+
await queryRunner.query(`ALTER TABLE "chat_conversation" ADD "photoId" uuid NOT NULL`);
9+
await queryRunner.query(`ALTER TABLE "chat_conversation" ADD CONSTRAINT "UQ_947568bb9d0cd0b94c7541084bf" UNIQUE ("photoId")`);
10+
await queryRunner.query(`ALTER TABLE "chat_conversation" ADD CONSTRAINT "FK_947568bb9d0cd0b94c7541084bf" FOREIGN KEY ("photoId") REFERENCES "chat_conversation_photo"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
11+
}
12+
13+
public async down(queryRunner: QueryRunner): Promise<void> {
14+
await queryRunner.query(`ALTER TABLE "chat_conversation" DROP CONSTRAINT "FK_947568bb9d0cd0b94c7541084bf"`);
15+
await queryRunner.query(`ALTER TABLE "chat_conversation" DROP CONSTRAINT "UQ_947568bb9d0cd0b94c7541084bf"`);
16+
await queryRunner.query(`ALTER TABLE "chat_conversation" DROP COLUMN "photoId"`);
17+
await queryRunner.query(`ALTER TABLE "chat_conversation" ADD "photoId" character varying`);
18+
}
19+
20+
}

0 commit comments

Comments
 (0)