Allow database URL to be specified via command line

This commit is contained in:
Adrian Macneil 2015-11-25 11:32:13 -08:00
parent 99a4f266e6
commit ece5d3cf0e
4 changed files with 36 additions and 9 deletions

View file

@ -16,7 +16,7 @@ import (
// CreateCommand creates the current database
func CreateCommand(ctx *cli.Context) error {
u, err := GetDatabaseURL()
u, err := GetDatabaseURL(ctx)
if err != nil {
return err
}
@ -31,7 +31,7 @@ func CreateCommand(ctx *cli.Context) error {
// DropCommand drops the current database (if it exists)
func DropCommand(ctx *cli.Context) error {
u, err := GetDatabaseURL()
u, err := GetDatabaseURL(ctx)
if err != nil {
return err
}
@ -86,8 +86,11 @@ func NewCommand(ctx *cli.Context) error {
}
// GetDatabaseURL returns the current environment database url
func GetDatabaseURL() (u *url.URL, err error) {
return url.Parse(os.Getenv("DATABASE_URL"))
func GetDatabaseURL(ctx *cli.Context) (u *url.URL, err error) {
env := ctx.GlobalString("env")
value := os.Getenv(env)
return url.Parse(value)
}
func doTransaction(db *sql.DB, txFunc func(shared.Transaction) error) error {
@ -116,7 +119,7 @@ func MigrateCommand(ctx *cli.Context) error {
return fmt.Errorf("No migration files found.")
}
u, err := GetDatabaseURL()
u, err := GetDatabaseURL(ctx)
if err != nil {
return err
}