Skip to content

Commit c017038

Browse files
authored
Fix error when trying to delete user with uploaded images (#4295)
* Fix error when trying to delete user with uploaded images `{"error":"database_error","description":"Database Error: Error while interacting with the database: error returned from database: update or delete on table \"users\" violates foreign key constraint \"uploaded_images_owner_id_fkey\" on table \"uploaded_images\""}` * Update certain things to use Ghost instead of deleting entirely * Fix mistake
1 parent a323bf6 commit c017038

6 files changed

+76
-19
lines changed

apps/labrinth/.sqlx/query-0461463e3e14f6c8ede5571a2905b8171e8caf4ebbd3ec844ef2cebd83980247.json renamed to apps/labrinth/.sqlx/query-4a28872d188834822be5df7be5d023ba6425bda15bf568eebbd8175912eb5700.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/labrinth/.sqlx/query-4de9fdac1831320d744cb6edd0cfe6e1fd670348f0ef881f67d7aec1acd6571f.json

Lines changed: 0 additions & 14 deletions
This file was deleted.

apps/labrinth/.sqlx/query-54bfa46679475b799f85494e1aafd093dd6023259a1e617eeb2c5491e5e5f704.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/labrinth/.sqlx/query-b8c62f703e8460a29a406b4b5a46fd30169f7ce6628f31c6749dada507cdc325.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/labrinth/.sqlx/query-fbc0c5d96263c6bc65787bbecdd264e8130a353058ac028d4fce4a38568019ee.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/labrinth/src/database/models/user_item.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,13 +599,25 @@ impl DBUser {
599599
sqlx::query!(
600600
"
601601
DELETE FROM reports
602-
WHERE user_id = $1 OR reporter = $1
602+
WHERE reporter = $1
603603
",
604604
id as DBUserId,
605605
)
606606
.execute(&mut **transaction)
607607
.await?;
608608

609+
sqlx::query!(
610+
"
611+
UPDATE reports
612+
SET user_id = $1
613+
WHERE user_id = $2
614+
",
615+
deleted_user as DBUserId,
616+
id as DBUserId,
617+
)
618+
.execute(&mut **transaction)
619+
.await?;
620+
609621
sqlx::query!(
610622
"
611623
DELETE FROM mod_follows
@@ -638,9 +650,11 @@ impl DBUser {
638650

639651
sqlx::query!(
640652
"
641-
DELETE FROM payouts
642-
WHERE user_id = $1
653+
UPDATE payouts
654+
SET user_id = $1
655+
WHERE user_id = $2
643656
",
657+
deleted_user as DBUserId,
644658
id as DBUserId,
645659
)
646660
.execute(&mut **transaction)
@@ -668,6 +682,18 @@ impl DBUser {
668682
.execute(&mut **transaction)
669683
.await?;
670684

685+
sqlx::query!(
686+
"
687+
UPDATE uploaded_images
688+
SET owner_id = $1
689+
WHERE owner_id = $2
690+
",
691+
deleted_user as DBUserId,
692+
id as DBUserId,
693+
)
694+
.execute(&mut **transaction)
695+
.await?;
696+
671697
sqlx::query!(
672698
"
673699
DELETE FROM sessions

0 commit comments

Comments
 (0)