fix forgot removed records when deleting user (#5429)

* fix forgot removed records when deleting user

* fix migration

* fix rewritekey lock on sqlite

* remove unused codes
This commit is contained in:
Lunny Xiao 2018-12-19 00:26:26 +08:00 committed by techknowlogick
parent e726e4b828
commit fe55ab2a68
19 changed files with 763 additions and 135 deletions

View file

@ -202,6 +202,8 @@ var migrations = []Migration{
NewMigration("add must_change_password column for users table", addMustChangePassword),
// v74 -> v75
NewMigration("add approval whitelists to protected branches", addApprovalWhitelistsToProtectedBranches),
// v75 -> v76
NewMigration("clear nonused data which not deleted when user was deleted", clearNonusedData),
}
// Migrate database to current version

33
models/migrations/v75.go Normal file
View file

@ -0,0 +1,33 @@
// Copyright 2018 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package migrations
import (
"github.com/go-xorm/builder"
"github.com/go-xorm/xorm"
)
func clearNonusedData(x *xorm.Engine) error {
condDelete := func(colName string) builder.Cond {
return builder.NotIn(colName, builder.Select("id").From("user"))
}
if _, err := x.Exec(builder.Delete(condDelete("uid")).From("team_user")); err != nil {
return err
}
if _, err := x.Exec(builder.Delete(condDelete("user_id")).From("collaboration")); err != nil {
return err
}
if _, err := x.Exec(builder.Delete(condDelete("user_id")).From("stop_watch")); err != nil {
return err
}
if _, err := x.Exec(builder.Delete(condDelete("owner_id")).From("gpg_key")); err != nil {
return err
}
return nil
}