mirror of
https://github.com/TECHNOFAB11/dbmate.git
synced 2025-12-12 08:00:04 +01:00
Allow database URL to be specified via command line
This commit is contained in:
parent
99a4f266e6
commit
ece5d3cf0e
4 changed files with 36 additions and 9 deletions
13
commands.go
13
commands.go
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue