chore: sqlstore cleanup (#60415)
* chore: remove unused test helper from sqlstore TimeNow() is no longer used in any tests in this package. * chore: move sqlstore.SQLBuilder to the infra/db package This required some minor refactoring; we need to be a little more explicit about passing around the dialect and engine. On the other hand, that's a few fewer uses of the `dialect` global constant! * chore: move UserDeletions into the only package using it * cleanup around moving sqlbuilder * remove dialect and sqlog global vars * rename userDeletions to serviceAccountDeletions
This commit is contained in:
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/apikey"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/serviceaccounts"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
@@ -162,11 +162,11 @@ func (s *ServiceAccountsStoreImpl) UpdateServiceAccount(
|
||||
return updatedUser, err
|
||||
}
|
||||
|
||||
func ServiceAccountDeletions() []string {
|
||||
func ServiceAccountDeletions(dialect migrator.Dialect) []string {
|
||||
deletes := []string{
|
||||
"DELETE FROM api_key WHERE service_account_id = ?",
|
||||
}
|
||||
deletes = append(deletes, sqlstore.UserDeletions()...)
|
||||
deletes = append(deletes, serviceAccountDeletions(dialect)...)
|
||||
return deletes
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ func (s *ServiceAccountsStoreImpl) deleteServiceAccount(sess *db.Session, orgId,
|
||||
if !has {
|
||||
return serviceaccounts.ErrServiceAccountNotFound
|
||||
}
|
||||
for _, sql := range ServiceAccountDeletions() {
|
||||
for _, sql := range ServiceAccountDeletions(s.sqlStore.GetDialect()) {
|
||||
_, err := sess.Exec(sql, user.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -530,3 +530,18 @@ func (s *ServiceAccountsStoreImpl) RevertApiKey(ctx context.Context, saId int64,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func serviceAccountDeletions(dialect migrator.Dialect) []string {
|
||||
deletes := []string{
|
||||
"DELETE FROM star WHERE user_id = ?",
|
||||
"DELETE FROM " + dialect.Quote("user") + " WHERE id = ?",
|
||||
"DELETE FROM org_user WHERE user_id = ?",
|
||||
"DELETE FROM dashboard_acl WHERE user_id = ?",
|
||||
"DELETE FROM preferences WHERE user_id = ?",
|
||||
"DELETE FROM team_member WHERE user_id = ?",
|
||||
"DELETE FROM user_auth WHERE user_id = ?",
|
||||
"DELETE FROM user_auth_token WHERE user_id = ?",
|
||||
"DELETE FROM quota WHERE user_id = ?",
|
||||
}
|
||||
return deletes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user