dbconf: allow configuration to override a driver's import field

pull/2/head
Liam Staskawicz 2013-04-07 14:34:56 -07:00
parent 4446df2ca6
commit 09e81b9cb9
4 changed files with 34 additions and 1 deletions

View File

@ -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.
## 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

View File

@ -10,3 +10,8 @@ development:
production:
driver: postgres
open: user=liam dbname=tester sslmode=verify-full
customimport:
driver: customdriver
open: customdriver open
import: github.com/custom/driver

View File

@ -65,7 +65,10 @@ func makeDBConfDetails(p, env string) (*DBConf, error) {
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() {
return nil, errors.New(fmt.Sprintf("Invalid DBConf: %v", d))

View File

@ -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)
}
}