Enforce schema if one is set

This commit is contained in:
Nise Void 2017-04-19 14:45:11 +02:00
parent 3dc4599329
commit 0234500a89

View File

@ -39,6 +39,17 @@ func Migrate(db *sql.DB, version int, o Options, asset AssetFunc) error {
table := o.TableName
if o.Schema != `` {
table = o.Schema + `.` + table
fmt.Println(`Switching to schema:`, o.Schema)
_, err := db.Exec(`CREATE SCHEMA IF NOT EXISTS ` + o.Schema)
if err != nil {
return err
}
_, err = db.Exec(`SET search_path TO ` + o.Schema + `,public`)
if err != nil {
return err
}
}
_, err := db.Exec(`CREATE TABLE IF NOT EXISTS ` + table + ` (Version integer NOT NULL PRIMARY KEY)`)