Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/fatih/color"
"github.com/healthimation/go-aws-config/src/awsconfig"
"github.com/turbine/migrate/driver"
"github.com/turbine/migrate/file"
"github.com/turbine/migrate/migrate"
Expand All @@ -22,6 +23,9 @@ var url = flag.String("url", "", "")
var migrationsPath = flag.String("path", "", "")
var version = flag.Bool("version", false, "Show migrate version")
var transactionType = flag.String("txn", "PerFile", "")
var environment = flag.String("env", "", "The environment you're running in")
var service = flag.String("service", "", "The service's name (combined with env to form AWS parameter store key \"/env/service/urlkey\")")
var dbURLKey = flag.String("urlkey", "DB_URL", "")

func main() {
flag.Parse()
Expand All @@ -42,6 +46,23 @@ func main() {
os.Exit(1)
}

// check AWS parameter for db URL
if len(*url) == 0 && len(*environment) > 0 && len(*service) > 0 {
conf := awsconfig.NewAWSLoader(*environment, *service)
err := conf.Initialize()
if err != nil {
fmt.Printf("Could not pull AWS parameter store configuration: %s\n", err.Error())
os.Exit(1)
}
dbURLby, err := conf.Get(*dbURLKey)
if err != nil || len(dbURLby) == 0 {
fmt.Printf("AWS parameter store key /%s/%s/%s was missing or not parsable\n", *environment, *service, *dbURLKey)
os.Exit(1)
}
dbURL := string(dbURLby)
url = &dbURL
}

switch command {
case "create":
verifyMigrationsPath(*migrationsPath)
Expand Down Expand Up @@ -224,7 +245,7 @@ func printTimer() {

func helpCmd() {
os.Stderr.WriteString(
`usage: migrate [-path=<path>] -url=<url> <command> [<args>]
`usage: migrate [-path=<path>] [-url=<url>] [-env=<environment> -service=<serviceName> [-urlkey=<urlkey>]] <command> [<args>]

Commands:
create <name> Create a new migration
Expand All @@ -238,5 +259,9 @@ Commands:
help Show this help

'-path' defaults to current working directory.
'-url' or '-env' and '-service' are required.
If you provide '-env' and '-service' the app will look up the '-urlkey' in AWS parameter store as '/env/service/urlkey'
You will need to provide a standard AWS credential provider to use the '-env' and '-service' parameters.
'-urlkey' defaults to DB_URL
`)
}