Skip to content

Commit

Permalink
register pgx in main cli, not internal
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-garcia committed Dec 5, 2023
1 parent 810f0e5 commit 90b3fcf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
1 change: 1 addition & 0 deletions cmd/migrate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
migrate
8 changes: 8 additions & 0 deletions cmd/migrate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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() {
Expand Down
17 changes: 0 additions & 17 deletions internal/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"database/sql"
"database/sql/driver"

Check failure on line 5 in internal/cli/main.go

View workflow job for this annotation

GitHub Actions / test (1.17.x)

imported and not used: "database/sql/driver"

Check failure on line 5 in internal/cli/main.go

View workflow job for this annotation

GitHub Actions / test (1.18.x)

imported and not used: "database/sql/driver"

Check failure on line 5 in internal/cli/main.go

View workflow job for this annotation

GitHub Actions / test (1.17.x)

imported and not used: "database/sql/driver"

Check failure on line 5 in internal/cli/main.go

View workflow job for this annotation

GitHub Actions / test (1.18.x)

imported and not used: "database/sql/driver"
"fmt"
"github.com/jackc/pgx/v4/stdlib"
"net/url"
"os"
"os/signal"
Expand All @@ -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"

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 90b3fcf

Please sign in to comment.