From 80475fa13a4a0dbe3d8f4d68fa64caebb11ceae9 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Mon, 3 Jun 2019 16:45:03 +0200 Subject: [PATCH] Database: Initialize xorm with an empty schema for postgres (#17357) xorm introduced some changes in https://github.com/go-xorm/xorm/pull/824 and https://github.com/go-xorm/xorm/pull/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 #16720 Co-Authored-By: Carl Bergquist (cherry picked from commit b7a9533476633df8a902e347932d6cd5d71a58f1) --- pkg/services/sqlstore/sqlstore.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/services/sqlstore/sqlstore.go b/pkg/services/sqlstore/sqlstore.go index 6ea6c4e3033..e71cafec70a 100644 --- a/pkg/services/sqlstore/sqlstore.go +++ b/pkg/services/sqlstore/sqlstore.go @@ -39,6 +39,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(®istry.Descriptor{ Name: "SqlStore", Instance: &SqlStore{},