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:
Sofia Papagiannaki 2020-01-22 17:56:12 +02:00 committed by GitHub
parent 5afcf79c59
commit 2283ceec09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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