User+team: remove startup migration for uid (#89953)

* Remove migration that is performed on startup
This commit is contained in:
Karl Persson 2024-07-03 09:11:52 +02:00 committed by GitHub
parent cfe8317d45
commit f18da6f4dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 0 additions and 55 deletions

View File

@ -11,7 +11,6 @@ import (
"github.com/grafana/grafana/pkg/infra/db"
ac "github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/dashboards/dashboardaccess"
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
"github.com/grafana/grafana/pkg/services/team"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
@ -567,25 +566,3 @@ func (ss *xormStore) getTeamMembers(ctx context.Context, query *team.GetTeamMemb
func (ss *xormStore) RegisterDelete(query string) {
ss.deletes = append(ss.deletes, query)
}
// This is just to ensure that all teams have a valid uid.
// To protect against upgrade / downgrade we need to run this for a couple of releases.
// FIXME: Remove this migration and make uid field required https://github.com/grafana/identity-access-team/issues/552
func (ss *xormStore) uidMigration() error {
return ss.db.WithDbSession(context.Background(), func(sess *db.Session) error {
switch ss.db.GetDBType() {
case migrator.SQLite:
_, err := sess.Exec("UPDATE team SET uid=printf('t%09d',id) WHERE uid IS NULL;")
return err
case migrator.Postgres:
_, err := sess.Exec("UPDATE team SET uid='t' || lpad('' || id::text,9,'0') WHERE uid IS NULL;")
return err
case migrator.MySQL:
_, err := sess.Exec("UPDATE team SET uid=concat('t',lpad(id,9,'0')) WHERE uid IS NULL;")
return err
default:
// this branch should be unreachable
return nil
}
})
}

View File

@ -18,11 +18,6 @@ type Service struct {
}
func ProvideService(db db.DB, cfg *setting.Cfg, tracer tracing.Tracer) (team.Service, error) {
store := &xormStore{db: db, cfg: cfg, deletes: []string{}}
if err := store.uidMigration(); err != nil {
return nil, err
}
return &Service{
store: &xormStore{db: db, cfg: cfg, deletes: []string{}},
tracer: tracer,

View File

@ -17,7 +17,6 @@ import (
"github.com/grafana/grafana/pkg/services/org"
"github.com/grafana/grafana/pkg/services/quota"
"github.com/grafana/grafana/pkg/services/serviceaccounts"
"github.com/grafana/grafana/pkg/services/sqlstore/migrator"
"github.com/grafana/grafana/pkg/services/supportbundles"
"github.com/grafana/grafana/pkg/services/team"
"github.com/grafana/grafana/pkg/services/user"
@ -65,10 +64,6 @@ func ProvideService(
return s, err
}
if err := s.uidMigration(db); err != nil {
return nil, err
}
bundleRegistry.RegisterSupportItemCollector(s.supportBundleCollector())
return s, nil
}
@ -529,25 +524,3 @@ func readQuotaConfig(cfg *setting.Cfg) (*quota.Map, error) {
limits.Set(globalQuotaTag, cfg.Quota.Global.User)
return limits, nil
}
// This is just to ensure that all users have a valid uid.
// To protect against upgrade / downgrade we need to run this for a couple of releases.
// FIXME: Remove this migration and make uid field required https://github.com/grafana/identity-access-team/issues/552
func (s *Service) uidMigration(store db.DB) error {
return store.WithDbSession(context.Background(), func(sess *db.Session) error {
switch store.GetDBType() {
case migrator.SQLite:
_, err := sess.Exec("UPDATE user SET uid=printf('u%09d',id) WHERE uid IS NULL;")
return err
case migrator.Postgres:
_, err := sess.Exec("UPDATE `user` SET uid='u' || lpad('' || id::text,9,'0') WHERE uid IS NULL;")
return err
case migrator.MySQL:
_, err := sess.Exec("UPDATE user SET uid=concat('u',lpad(id,9,'0')) WHERE uid IS NULL;")
return err
default:
// this branch should be unreachable
return nil
}
})
}