Skip to content

Commit

Permalink
Database: Initialize xorm with an empty schema for postgres (grafana#…
Browse files Browse the repository at this point in the history
…17357)

xorm introduced some changes in
go-xorm/xorm#824 and
go-xorm/xorm#876 which by default will use
public as the postgres schema and this was a breaking change compared
to before. Grafana has implemented a custom postgres dialect so above
changes wasn't a problem here. However, Grafana's custom database
migration was using xorm dialect to check if the migration table exists
or not.
For those using a custom search_path (schema) in postgres configured on
server, database or user level the migration table check would not find
the migration table since it was looking in public schema due to xorm
changes above. This had the consequence that Grafana's database
migration failed the second time since migration had already run
migrations in another schema.
This change will make xorm use an empty default schema for postgres and
by that mimic the functionality of how it was functioning before
xorm's changes above.
Fixes grafana#16720

Co-Authored-By: Carl Bergquist <[email protected]>
  • Loading branch information
marefr and bergquist authored Jun 3, 2019
1 parent fbf37eb commit b7a9533
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/services/sqlstore/sqlstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ var (
const ContextSessionName = "db-session"

func init() {
// This change will make xorm use an empty default schema for postgres and
// by that mimic the functionality of how it was functioning before
// xorm's changes above.
xorm.DefaultPostgresSchema = ""

registry.Register(&registry.Descriptor{
Name: "SqlStore",
Instance: &SqlStore{},
Expand Down

0 comments on commit b7a9533

Please sign in to comment.