Restore search_path after finishing migrations

This commit is contained in:
Nise Void 2018-02-27 18:16:58 +01:00
parent 42f58417e9
commit fdc83faba0

View File

@ -38,6 +38,9 @@ func Migrate(db *sql.DB, version int, o Options, asset AssetFunc) error {
var err error
searchPath := `public`
_ = db.QueryRow(`SHOW search_path`).Scan(&searchPath)
if o.Schema != `` {
_, _ = db.Exec(`CREATE SCHEMA IF NOT EXISTS ` + o.Schema)
@ -88,7 +91,7 @@ func Migrate(db *sql.DB, version int, o Options, asset AssetFunc) error {
}
if o.Schema != `` {
_, err = tx.Exec(`SET search_path TO ` + o.Schema + `,public`)
_, err = tx.Exec(`SET search_path TO ` + searchPath)
if err != nil {
return err
}