mirror of https://github.com/pressly/goose.git
dbconf: allow configuration to override a driver's import field
parent
4446df2ca6
commit
09e81b9cb9
11
README.md
11
README.md
|
@ -127,6 +127,17 @@ You may include as many environments as you like, and you can use the `-env` com
|
||||||
|
|
||||||
goose will expand environment variables in the `open` element. For an example, see the Heroku section below.
|
goose will expand environment variables in the `open` element. For an example, see the Heroku section below.
|
||||||
|
|
||||||
|
## Other Drivers
|
||||||
|
goose knows about some common SQL drivers, but it can still be used to run Go-based migrations with any driver supported by database/sql.
|
||||||
|
|
||||||
|
To run Go-based migrations with another driver, specify its import path, as shown below.
|
||||||
|
|
||||||
|
customdriver:
|
||||||
|
driver: custom
|
||||||
|
open: custom open string
|
||||||
|
import: github.com/custom/driver
|
||||||
|
|
||||||
|
NOTE: Because migrations written in SQL are executed directly by the goose binary, only drivers compiled into goose may be used for these migrations.
|
||||||
|
|
||||||
## Using goose with Heroku
|
## Using goose with Heroku
|
||||||
|
|
||||||
|
|
|
@ -10,3 +10,8 @@ development:
|
||||||
production:
|
production:
|
||||||
driver: postgres
|
driver: postgres
|
||||||
open: user=liam dbname=tester sslmode=verify-full
|
open: user=liam dbname=tester sslmode=verify-full
|
||||||
|
|
||||||
|
customimport:
|
||||||
|
driver: customdriver
|
||||||
|
open: customdriver open
|
||||||
|
import: github.com/custom/driver
|
||||||
|
|
|
@ -65,7 +65,10 @@ func makeDBConfDetails(p, env string) (*DBConf, error) {
|
||||||
|
|
||||||
d := NewDBDriver(drv, open)
|
d := NewDBDriver(drv, open)
|
||||||
|
|
||||||
// XXX: allow an import entry to override DBDriver.Import
|
// allow the configuration to override the Import for this driver
|
||||||
|
if imprt, err := f.Get(fmt.Sprintf("%s.import", env)); err == nil {
|
||||||
|
d.Import = imprt
|
||||||
|
}
|
||||||
|
|
||||||
if !d.IsValid() {
|
if !d.IsValid() {
|
||||||
return nil, errors.New(fmt.Sprintf("Invalid DBConf: %v", d))
|
return nil, errors.New(fmt.Sprintf("Invalid DBConf: %v", d))
|
||||||
|
|
|
@ -21,3 +21,17 @@ func TestBasics(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestImportOverride(t *testing.T) {
|
||||||
|
|
||||||
|
dbconf, err := makeDBConfDetails("db-sample", "customimport")
|
||||||
|
if err != nil {
|
||||||
|
t.Error("couldn't create DBConf")
|
||||||
|
}
|
||||||
|
|
||||||
|
got := dbconf.Driver.Import
|
||||||
|
want := "github.com/custom/driver"
|
||||||
|
if got != want {
|
||||||
|
t.Errorf("bad custom import. want %v got %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue