diff --git a/cmd/migrate/.gitignore b/cmd/migrate/.gitignore new file mode 100644 index 000000000..219f6a587 --- /dev/null +++ b/cmd/migrate/.gitignore @@ -0,0 +1 @@ +migrate diff --git a/cmd/migrate/main.go b/cmd/migrate/main.go index a91a3650e..b6188d95f 100644 --- a/cmd/migrate/main.go +++ b/cmd/migrate/main.go @@ -5,6 +5,10 @@ import ( "strings" "github.com/golang-migrate/migrate/v4/internal/cli" + "github.com/infobloxopen/hotload" + _ "github.com/infobloxopen/hotload/fsnotify" + "github.com/jackc/pgx/v4/stdlib" + "github.com/lib/pq" "github.com/sirupsen/logrus" "github.com/spf13/pflag" "github.com/spf13/viper" @@ -25,6 +29,10 @@ func init() { // logrus formatter customFormatter := new(logrus.JSONFormatter) logrus.SetFormatter(customFormatter) + + hotload.RegisterSQLDriver("pgx", stdlib.GetDefaultDriver()) + hotload.RegisterSQLDriver("postgres", pq.Driver{}) + hotload.RegisterSQLDriver("postgresql", pq.Driver{}) } func main() { diff --git a/internal/cli/main.go b/internal/cli/main.go index dd77a100e..cdc485497 100644 --- a/internal/cli/main.go +++ b/internal/cli/main.go @@ -4,7 +4,6 @@ import ( "database/sql" "database/sql/driver" "fmt" - "github.com/jackc/pgx/v4/stdlib" "net/url" "os" "os/signal" @@ -13,9 +12,6 @@ import ( "syscall" "time" - "github.com/infobloxopen/hotload" - _ "github.com/infobloxopen/hotload/fsnotify" - "github.com/lib/pq" flag "github.com/spf13/pflag" "github.com/spf13/viper" @@ -74,10 +70,6 @@ func dbMakeConnectionString(driver, user, password, address, name, ssl string) s ) } -func registerHotloadWithDriver(name string, driver driver.Driver) { - hotload.RegisterSQLDriver(name, driver) -} - // Main function of a cli application. It is public for backwards compatibility with `cli` package func Main(version string) { help := viper.GetBool("help") @@ -167,15 +159,6 @@ Database drivers: `+strings.Join(database.List(), ", ")+"\n", createUsage, gotoU if err != nil { log.fatalErr(fmt.Errorf("could not parse hotload dsn %v: %s", databasePtr, err)) } - hostname := u.Hostname() - switch hostname { - case "postgres": - registerHotloadWithDriver(hostname, pq.Driver{}) - case "pgx": - registerHotloadWithDriver(hostname, stdlib.GetDefaultDriver()) - default: - log.fatalErr(fmt.Errorf("unsupported hotload base driver: %s", hostname)) - } db, err := sql.Open(driver, databasePtr) if err != nil { log.fatalErr(fmt.Errorf("could not open hotload dsn %s: %s", databasePtr, err))