Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sqlcon): Parse DSN manually instead of using url.Parse #119

Merged
merged 1 commit into from
Mar 1, 2020
Merged
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
15 changes: 5 additions & 10 deletions sqlcon/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package sqlcon

import (
"fmt"
"net/url"
"time"

"github.com/ory/x/viperx"
Expand Down Expand Up @@ -52,23 +51,19 @@ Examples:
db = args[0]
}

dbu, err := url.Parse(db)
if err != nil {
logger.WithError(err).WithField("dsn", db).Fatal(`Unable to parse configuration item "dsn", make sure it has the right format`)
}

if dbu.Scheme != "postgres" && dbu.Scheme != "mysql" && dbu.Scheme != "cockroach" {
logger.WithField("dsn", dbu.Scheme+"://*:*@"+dbu.Host+dbu.Path+"?"+dbu.RawQuery).Fatal("Migrations can only be run against PostgreSQL, MySQL or CockroachDB databases")
driverName := GetDriverName(db)
if driverName != "postgres" && driverName != "mysql" && driverName != "cockroach" {
logger.WithField("dsn", classifyDSN(db)).Fatal("Migrations can only be run against PostgreSQL, MySQL or CockroachDB databases")
}

sdb, err := NewSQLConnection(db, logger)
if err != nil {
logger.WithError(err).WithField("dsn", dbu.Scheme+"://*:*@"+dbu.Host+dbu.Path+"?"+dbu.RawQuery).Fatal("Unable to initialize database configuration")
logger.WithError(err).WithField("dsn", classifyDSN(db)).Fatal("Unable to initialize database configuration")
}

dbx, err := sdb.GetDatabaseRetry(time.Second, time.Minute*5)
if err != nil {
logger.WithError(err).WithField("dsn", dbu.Scheme+"://*:*@"+dbu.Host+dbu.Path+"?"+dbu.RawQuery).Fatal("Unable to connect to the SQL database")
logger.WithError(err).WithField("dsn", classifyDSN(db)).Fatal("Unable to connect to the SQL database")
}

for name, runner := range runners {
Expand Down