mirror of https://github.com/pressly/goose.git
Merged in josharian/goose/flexible-dbconf-open (pull request #2: Make dbconf's open more flexible)
commit
b1edd0e4fa
22
README.md
22
README.md
|
@ -124,3 +124,25 @@ A sample dbconf.yml looks like
|
|||
Here, `development` specifies the name of the environment, and the `driver` and `open` elements are passed directly to database/sql to access the specified database.
|
||||
|
||||
You may include as many environments as you like, and you can use the `-env` command line option to specify which one to use. goose defaults to using an environment called `development`.
|
||||
|
||||
goose will expand environment variables in the `open` element. For an example, see the Heroku section below.
|
||||
|
||||
|
||||
## Using goose with Heroku
|
||||
|
||||
goose plays nicely with Heroku. These instructions assume that you're using [Keith Rarick's Heroku Go buildpack](https://github.com/kr/heroku-buildpack-go). First, make sure that Heroku builds the goose executable during deployment by adding an (unused) import to your app:
|
||||
|
||||
import _ "bitbucket.org/liamstask/goose"
|
||||
|
||||
[Set up your Heroku database(s) as usual.](https://devcenter.heroku.com/articles/heroku-postgresql)
|
||||
|
||||
Then make use of environment variable expansion in your `dbconf.yml`, such as:
|
||||
|
||||
production:
|
||||
driver: postgres
|
||||
open: $DATABASE_URL
|
||||
|
||||
To run migrations in production, use `heroku run`, e.g.:
|
||||
|
||||
heroku run goose -env production up
|
||||
|
||||
|
|
12
dbconf.go
12
dbconf.go
|
@ -3,7 +3,9 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/bmizerany/pq"
|
||||
"github.com/kylelemons/go-gypsy/yaml"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
|
@ -37,6 +39,16 @@ func MakeDBConf() (*DBConf, error) {
|
|||
if oerr != nil {
|
||||
return nil, oerr
|
||||
}
|
||||
open = os.ExpandEnv(open)
|
||||
|
||||
// Automatically parse postgres urls
|
||||
if drv == "postgres" {
|
||||
parsed_open, parse_err := pq.ParseURL(open)
|
||||
// Assumption: If we can parse the URL, we should
|
||||
if parse_err == nil && parsed_open != "" {
|
||||
open = parsed_open
|
||||
}
|
||||
}
|
||||
|
||||
return &DBConf{
|
||||
MigrationsDir: path.Join(*dbPath, "migrations"),
|
||||
|
|
Loading…
Reference in New Issue