diff --git a/src/util/entities/CloudAttachment.ts b/src/util/entities/CloudAttachment.ts index 02c52743..887bce2c 100644 --- a/src/util/entities/CloudAttachment.ts +++ b/src/util/entities/CloudAttachment.ts @@ -34,7 +34,7 @@ export class CloudAttachment extends BaseClass { @RelationId((att: CloudAttachment) => att.user) userId: string; - @JoinColumn({ name: "userId" }) + @JoinColumn({ name: "user_id" }) @ManyToOne(() => User, { nullable: true, onDelete: "SET NULL" }) user?: User; @@ -42,7 +42,7 @@ export class CloudAttachment extends BaseClass { @RelationId((att: CloudAttachment) => att.channel) channelId?: string; // channel the file is uploaded to - @JoinColumn({ name: "channelId" }) + @JoinColumn({ name: "channel_id" }) @ManyToOne(() => Channel, { nullable: true, onDelete: "SET NULL" }) channel?: Channel; // channel the file is uploaded to diff --git a/src/util/migration/postgres/1758654621365-CloudAttachmentsFixIdRefs.ts b/src/util/migration/postgres/1758654621365-CloudAttachmentsFixIdRefs.ts new file mode 100644 index 00000000..b3be7ab0 --- /dev/null +++ b/src/util/migration/postgres/1758654621365-CloudAttachmentsFixIdRefs.ts @@ -0,0 +1,24 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class CloudAttachmentsFixIdRefs1758654621365 implements MigrationInterface { + name = 'CloudAttachmentsFixIdRefs1758654621365' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "cloud_attachments" DROP CONSTRAINT "FK_cab965a18f8ca30293bff3d50a8"`); + await queryRunner.query(`ALTER TABLE "cloud_attachments" DROP CONSTRAINT "FK_e6b32df2004e8ad0f488b4a2019"`); + await queryRunner.query(`ALTER TABLE "cloud_attachments" DROP COLUMN "channelId"`); + await queryRunner.query(`ALTER TABLE "cloud_attachments" DROP COLUMN "userId"`); + await queryRunner.query(`ALTER TABLE "cloud_attachments" ADD CONSTRAINT "FK_8bf8cc8767e48cb482ff644fce6" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "cloud_attachments" ADD CONSTRAINT "FK_998d5fe91008ba5b09e1322104c" FOREIGN KEY ("channel_id") REFERENCES "channels"("id") ON DELETE SET NULL ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "cloud_attachments" DROP CONSTRAINT "FK_998d5fe91008ba5b09e1322104c"`); + await queryRunner.query(`ALTER TABLE "cloud_attachments" DROP CONSTRAINT "FK_8bf8cc8767e48cb482ff644fce6"`); + await queryRunner.query(`ALTER TABLE "cloud_attachments" ADD "userId" character varying`); + await queryRunner.query(`ALTER TABLE "cloud_attachments" ADD "channelId" character varying`); + await queryRunner.query(`ALTER TABLE "cloud_attachments" ADD CONSTRAINT "FK_e6b32df2004e8ad0f488b4a2019" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "cloud_attachments" ADD CONSTRAINT "FK_cab965a18f8ca30293bff3d50a8" FOREIGN KEY ("channelId") REFERENCES "channels"("id") ON DELETE SET NULL ON UPDATE NO ACTION`); + } + +}