mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 17:22:09 +08:00
Chore: Ignore unique constrain failure when creating the main organization (#68644)
Chore: Ignore unique constrain failure when creatin the main organization
This commit is contained in:

committed by
GitHub

parent
b7ca2d89b1
commit
633b7875e7
@ -157,6 +157,7 @@ func (ss *SQLStore) getOrCreateOrg(sess *DBSession, orgName string) (int64, erro
|
||||
if has {
|
||||
return org.ID, nil
|
||||
}
|
||||
ss.log.Debug("auto assigned organization not found")
|
||||
|
||||
if ss.Cfg.AutoAssignOrgId != 1 {
|
||||
ss.log.Error("Could not create user: organization ID does not exist", "orgID",
|
||||
@ -168,6 +169,11 @@ func (ss *SQLStore) getOrCreateOrg(sess *DBSession, orgName string) (int64, erro
|
||||
org.Name = mainOrgName
|
||||
org.ID = int64(ss.Cfg.AutoAssignOrgId)
|
||||
if err := sess.InsertId(&org, ss.Dialect); err != nil {
|
||||
ss.log.Error("failed to insert organization with provided id", "org_id", org.ID, "err", err)
|
||||
// ignore failure if for some reason the organization exists
|
||||
if ss.GetDialect().IsUniqueConstraintViolation(err) {
|
||||
return org.ID, nil
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user