Merge pull request #1353 from CyberL1/fix/refereced-messages-deletion

Allow to delete messages that have replies
This commit is contained in:
Madeline 2025-10-20 23:14:33 +11:00 committed by GitHub
commit 47fce8eec0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View File

@ -169,7 +169,7 @@ export class Message extends BaseClass {
};
@JoinColumn({ name: "message_reference_id" })
@ManyToOne(() => Message)
@ManyToOne(() => Message, { onDelete: "SET NULL" })
referenced_message?: Message | null;
@Column({ type: "simple-json", nullable: true })
@ -272,7 +272,6 @@ export class Message extends BaseClass {
if (!opts.member_id) opts.member_id = message.author_id;
if (!opts.member) opts.member = await Member.findOneOrFail({ where: { id: opts.member_id! } });
if (!opts.guild) {
if (opts.guild_id) opts.guild = await Guild.findOneOrFail({ where: { id: opts.guild_id! } });
else if (opts.channel?.guild?.id) opts.guild = opts.channel.guild;

View File

@ -0,0 +1,19 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class MessageReferenceFix1760961911873 implements MigrationInterface {
name = "MessageReferenceFix1760961911873";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "messages" DROP CONSTRAINT "FK_61a92bb65b302a76d9c1fcd3174"`);
await queryRunner.query(
`ALTER TABLE "messages" ADD CONSTRAINT "FK_61a92bb65b302a76d9c1fcd3174" FOREIGN KEY ("message_reference_id") REFERENCES "messages"("id") ON DELETE SET NULL ON UPDATE NO ACTION`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "messages" DROP CONSTRAINT "FK_61a92bb65b302a76d9c1fcd3174"`);
await queryRunner.query(
`ALTER TABLE "messages" ADD CONSTRAINT "FK_61a92bb65b302a76d9c1fcd3174" FOREIGN KEY ("message_reference_id") REFERENCES "messages"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
}
}