Commit 2283ceec by Sofia Papagiannaki Committed by GitHub

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>
parent 5afcf79c
......@@ -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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment