You've already forked AstralRinth
forked from didirus/AstralRinth
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
This commit is contained in:
@@ -599,13 +599,25 @@ impl DBUser {
|
||||
sqlx::query!(
|
||||
"
|
||||
DELETE FROM reports
|
||||
WHERE user_id = $1 OR reporter = $1
|
||||
WHERE reporter = $1
|
||||
",
|
||||
id as DBUserId,
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE reports
|
||||
SET user_id = $1
|
||||
WHERE user_id = $2
|
||||
",
|
||||
deleted_user as DBUserId,
|
||||
id as DBUserId,
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
DELETE FROM mod_follows
|
||||
@@ -638,9 +650,11 @@ impl DBUser {
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
DELETE FROM payouts
|
||||
WHERE user_id = $1
|
||||
UPDATE payouts
|
||||
SET user_id = $1
|
||||
WHERE user_id = $2
|
||||
",
|
||||
deleted_user as DBUserId,
|
||||
id as DBUserId,
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
@@ -668,6 +682,18 @@ impl DBUser {
|
||||
.execute(&mut **transaction)
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
UPDATE uploaded_images
|
||||
SET owner_id = $1
|
||||
WHERE owner_id = $2
|
||||
",
|
||||
deleted_user as DBUserId,
|
||||
id as DBUserId,
|
||||
)
|
||||
.execute(&mut **transaction)
|
||||
.await?;
|
||||
|
||||
sqlx::query!(
|
||||
"
|
||||
DELETE FROM sessions
|
||||
|
||||
Reference in New Issue
Block a user