Skip to content

Commit

Permalink
Delete gists when user is deleted (thomiceli#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomiceli committed Sep 25, 2023
1 parent dd050bb commit 6c450c6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/db/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (user *User) BeforeDelete(tx *gorm.DB) error {
}

// Decrement forks counter for all gists forked by this user
return tx.Model(&Gist{}).
err = tx.Model(&Gist{}).
Omit("updated_at").
Where("id IN (?)", tx.
Select("forked_id").
Expand All @@ -48,6 +48,12 @@ func (user *User) BeforeDelete(tx *gorm.DB) error {
).
UpdateColumn("nb_forks", gorm.Expr("nb_forks - 1")).
Error
if err != nil {
return err
}

// Delete all gists created by this user
return tx.Where("user_id = ?", user.ID).Delete(&Gist{}).Error
}

func UserExists(username string) (bool, error) {
Expand Down

0 comments on commit 6c450c6

Please sign in to comment.