Chore: Ignore unique constrain failure when creating the main organization (#68644)

Chore: Ignore unique constrain failure when creatin the main organization
pull/68687/head
Sofia Papagiannaki 2 years ago committed by GitHub
parent b7ca2d89b1
commit 633b7875e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      pkg/services/sqlstore/user.go

@ -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 {

Loading…
Cancel
Save