From 6f67731d6afde3dc519e9f52353ef5506a0f9888 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Thu, 10 Jan 2013 12:03:02 -0800 Subject: [PATCH] Autoparse postgres urls --- dbconf.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dbconf.go b/dbconf.go index 53d279c..66438a3 100644 --- a/dbconf.go +++ b/dbconf.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "github.com/bmizerany/pq" "github.com/kylelemons/go-gypsy/yaml" "os" "path" @@ -40,6 +41,15 @@ func MakeDBConf() (*DBConf, error) { } 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"), Env: *dbEnv,