Enforce schema if one is set
This commit is contained in:
parent
3dc4599329
commit
0234500a89
1 changed files with 11 additions and 0 deletions
11
migrate.go
11
migrate.go
|
@ -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)`)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue