Expand environment variables in dbconf.yml's open

The immediate goal here is to make using goose
with Heroku easier, where the database connection
url is provided by an environment variable. More
generally, this makes it easier to avoid committing
sensitive information like database credentials.
pull/2/head
Josh Bleecher Snyder 2013-01-10 10:11:40 -08:00
parent 17747efe29
commit f787354860
2 changed files with 24 additions and 0 deletions

View File

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

View File

@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"github.com/kylelemons/go-gypsy/yaml"
"os"
"path"
)
@ -37,6 +38,7 @@ func MakeDBConf() (*DBConf, error) {
if oerr != nil {
return nil, oerr
}
open = os.ExpandEnv(open)
return &DBConf{
MigrationsDir: path.Join(*dbPath, "migrations"),