mirror of
https://github.com/grafana/grafana.git
synced 2025-01-18 20:43:26 -06:00
SQLStore: Fix PostgreSQL failure to create organisation for first time (#21648)
* Fix PostgreSQL failure to create organisation for first time Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
parent
5afcf79c59
commit
2283ceec09
@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/go-xorm/xorm"
|
||||
"github.com/grafana/grafana/pkg/util/errutil"
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
@ -155,3 +156,15 @@ func (db *Postgres) IsUniqueConstraintViolation(err error) bool {
|
||||
func (db *Postgres) IsDeadlock(err error) bool {
|
||||
return db.isThisError(err, "40P01")
|
||||
}
|
||||
|
||||
func (db *Postgres) PostInsertId(table string, sess *xorm.Session) error {
|
||||
if table != "org" {
|
||||
return nil
|
||||
}
|
||||
|
||||
// sync primary key sequence of org table
|
||||
if _, err := sess.Exec("SELECT setval('org_id_seq', (SELECT max(id) FROM org));"); err != nil {
|
||||
return errutil.Wrapf(err, "failed to sync primary key for org table")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user