From 7ed2a4a84f2890017e16f2382217f460fd0caf51 Mon Sep 17 00:00:00 2001 From: Undefined Date: Fri, 16 Dec 2022 15:37:08 +0100 Subject: [PATCH] Add FK abuse_user_report.targetUserId -> user.id (closes #9227) --- ...73000-AddFkAbuseUserReportTargetUserIdToUserId.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 packages/backend/migration/1671199573000-AddFkAbuseUserReportTargetUserIdToUserId.js diff --git a/packages/backend/migration/1671199573000-AddFkAbuseUserReportTargetUserIdToUserId.js b/packages/backend/migration/1671199573000-AddFkAbuseUserReportTargetUserIdToUserId.js new file mode 100644 index 0000000000..68f560b478 --- /dev/null +++ b/packages/backend/migration/1671199573000-AddFkAbuseUserReportTargetUserIdToUserId.js @@ -0,0 +1,12 @@ +export class addFkAbuseUserReportTargetUserIdToUserId1671199573000 { + name = 'addFkAbuseUserReportTargetUserIdToUserId1671199573000' + + async up(queryRunner) { + await queryRunner.query(`DELETE FROM abuse_user_report WHERE NOT EXISTS (SELECT 1 FROM "user" WHERE "user"."id" = "abuse_user_report"."targetUserId")`); + await queryRunner.query(`ALTER TABLE abuse_user_report ADD CONSTRAINT fk_7f4e851a35d81b64dda28eee0 FOREIGN KEY ("targetUserId") REFERENCES "user"("id") ON DELETE CASCADE`); + } + + async down(queryRunner) { + await queryRunner.query(`ALTER TABLE abuse_user_report DROP CONSTRAINT fk_7f4e851a35d81b64dda28eee0`); + } +}