fix (backend): prevent chat messages from being deleted when attached file is deleted
This commit is contained in:
parent
6eee5c651c
commit
24f79d4796
4 changed files with 28 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
BEGIN;
|
BEGIN;
|
||||||
|
|
||||||
DELETE FROM "migrations" WHERE name IN (
|
DELETE FROM "migrations" WHERE name IN (
|
||||||
|
'FixChatFileConstraint1712855579316',
|
||||||
'DropTimeZone1712425488543',
|
'DropTimeZone1712425488543',
|
||||||
'ExpandNoteEdit1711936358554',
|
'ExpandNoteEdit1711936358554',
|
||||||
'markLocalFilesNsfwByDefault1709305200000',
|
'markLocalFilesNsfwByDefault1709305200000',
|
||||||
|
@ -21,6 +22,10 @@ DELETE FROM "migrations" WHERE name IN (
|
||||||
'RemoveNativeUtilsMigration1705877093218'
|
'RemoveNativeUtilsMigration1705877093218'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-- fix-chat-file-constraint
|
||||||
|
ALTER TABLE "messaging_message" DROP CONSTRAINT "FK_535def119223ac05ad3fa9ef64b";
|
||||||
|
ALTER TABLE "messaging_message" ADD CONSTRAINT "FK_535def119223ac05ad3fa9ef64b" FOREIGN KEY ("fileId") REFERENCES "drive_file"("id") ON DELETE CASCADE ON UPDATE NO ACTION;
|
||||||
|
|
||||||
-- drop-time-zone
|
-- drop-time-zone
|
||||||
ALTER TABLE "abuse_user_report" ALTER "createdAt" TYPE timestamp with time zone;
|
ALTER TABLE "abuse_user_report" ALTER "createdAt" TYPE timestamp with time zone;
|
||||||
ALTER TABLE "access_token" ALTER "createdAt" TYPE timestamp with time zone;
|
ALTER TABLE "access_token" ALTER "createdAt" TYPE timestamp with time zone;
|
||||||
|
|
|
@ -35,7 +35,7 @@ pub enum Relation {
|
||||||
from = "Column::FileId",
|
from = "Column::FileId",
|
||||||
to = "super::drive_file::Column::Id",
|
to = "super::drive_file::Column::Id",
|
||||||
on_update = "NoAction",
|
on_update = "NoAction",
|
||||||
on_delete = "Cascade"
|
on_delete = "SetNull"
|
||||||
)]
|
)]
|
||||||
DriveFile,
|
DriveFile,
|
||||||
#[sea_orm(
|
#[sea_orm(
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
import type { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class FixChatFileConstraint1712855579316 implements MigrationInterface {
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "messaging_message" DROP CONSTRAINT "FK_535def119223ac05ad3fa9ef64b"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "messaging_message" ADD CONSTRAINT "FK_535def119223ac05ad3fa9ef64b" FOREIGN KEY ("fileId") REFERENCES "drive_file"("id") ON DELETE SET NULL ON UPDATE NO ACTION`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "messaging_message" DROP CONSTRAINT "FK_535def119223ac05ad3fa9ef64b"`,
|
||||||
|
);
|
||||||
|
await queryRunner.query(
|
||||||
|
`ALTER TABLE "messaging_message" ADD CONSTRAINT "FK_535def119223ac05ad3fa9ef64b" FOREIGN KEY ("fileId") REFERENCES "drive_file"("id") ON DELETE CASCADE ON UPDATE NO ACTION`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -97,7 +97,7 @@ export class MessagingMessage {
|
||||||
public group: Relation<UserGroup | null>;
|
public group: Relation<UserGroup | null>;
|
||||||
|
|
||||||
@ManyToOne(() => DriveFile, {
|
@ManyToOne(() => DriveFile, {
|
||||||
onDelete: "CASCADE", // TODO: change this to SET NULL
|
onDelete: "SET NULL",
|
||||||
nullable: true,
|
nullable: true,
|
||||||
})
|
})
|
||||||
@JoinColumn()
|
@JoinColumn()
|
||||||
|
|
Loading…
Reference in a new issue