Skip to content

Commit

Permalink
cmd: Improve migration command (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Nov 4, 2019
1 parent b79c5d1 commit 2b631de
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 17 deletions.
16 changes: 4 additions & 12 deletions cmd/client/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package client
import (
"bufio"
"fmt"
"net/url"
"os"
"strings"

"github.com/ory/x/sqlcon"
"github.com/spf13/cobra"

"github.com/ory/viper"
Expand Down Expand Up @@ -55,16 +55,8 @@ func (h *MigrateHandler) MigrateSQL(cmd *cobra.Command, args []string) {
return
}

u, err := url.Parse(d.Configuration().DSN())
if err != nil {
fmt.Println(cmd.UsageString())
fmt.Println("")
fmt.Println(err)
os.Exit(1)
return
}

plan, err := reg.SchemaMigrationPlan(u.Scheme)
scheme := sqlcon.GetDriverName(d.Configuration().DSN())
plan, err := reg.SchemaMigrationPlan(scheme)
cmdx.Must(err, "An error occurred planning migrations: %s", err)

fmt.Println("The following migration is planned:")
Expand All @@ -80,7 +72,7 @@ func (h *MigrateHandler) MigrateSQL(cmd *cobra.Command, args []string) {
}
}

n, err := reg.CreateSchemas(u.Scheme)
n, err := reg.CreateSchemas(scheme)
cmdx.Must(err, "An error occurred while connecting to SQL: %s", err)
fmt.Printf("Successfully applied %d SQL migrations!\n", n)
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/ory/x/logrusx"

"github.com/spf13/cobra"

"github.com/ory/hive/driver/configuration"
)

var logger *logrus.Logger
Expand Down Expand Up @@ -44,6 +46,8 @@ func init() {

cobra.OnInitialize(func() {
viperx.InitializeConfig("hive", "", nil)
configuration.BindEnvs()

if logger == nil {
logger = logrusx.New()
}
Expand Down
2 changes: 1 addition & 1 deletion driver/sql_migration_files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ require (
github.com/go-swagger/go-swagger v0.19.0
github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013 // indirect
github.com/gobuffalo/packr/v2 v2.0.0-rc.15
github.com/golang/gddo v0.0.0-20181116215533-9bd4a3295021
github.com/golang/gddo v0.0.0-20190904175337-72a348e765d2
github.com/golang/mock v1.3.1
github.com/google/go-github/v27 v27.0.1
github.com/google/uuid v1.1.0
github.com/google/uuid v1.1.1
github.com/gorilla/context v1.1.1
github.com/gorilla/handlers v1.4.1 // indirect
github.com/gorilla/sessions v1.1.3
Expand All @@ -32,6 +32,8 @@ require (
github.com/julienschmidt/httprouter v1.2.0
github.com/justinas/nosurf v0.0.0-20190118163749-6453469bdcc9
github.com/leodido/go-urn v1.1.0 // indirect
github.com/lib/pq v1.2.0 // indirect
github.com/luna-duclos/instrumentedsql v1.1.1 // indirect
github.com/mattn/go-runewidth v0.0.4 // indirect
github.com/mattn/goveralls v0.0.2
github.com/olekukonko/tablewriter v0.0.1
Expand All @@ -42,24 +44,32 @@ require (
github.com/ory/graceful v0.1.1
github.com/ory/herodot v0.6.2
github.com/ory/viper v1.5.6
github.com/ory/x v0.0.72
github.com/ory/x v0.0.76
github.com/pelletier/go-toml v1.5.0 // indirect
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
github.com/pkg/errors v0.8.1
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
github.com/rubenv/sql-migrate v0.0.0-20190212093014-1007f53448d7
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5 // indirect
github.com/sqs/goreturns v0.0.0-20181028201513-538ac6014518
github.com/stretchr/testify v1.3.0
github.com/stretchr/testify v1.4.0
github.com/subosito/gotenv v1.2.0 // indirect
github.com/tidwall/gjson v1.2.1
github.com/tidwall/match v1.0.1 // indirect
github.com/tidwall/pretty v0.0.0-20190325153808-1166b9ac2b65 // indirect
github.com/tidwall/sjson v1.0.4
github.com/toqueteos/webbrowser v1.1.0 // indirect
github.com/urfave/negroni v1.0.0
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4
golang.org/x/net v0.0.0-20191014212845-da9a3fd4c582 // indirect
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
golang.org/x/sys v0.0.0-20191020152052-9984515f0562 // indirect
golang.org/x/tools v0.0.0-20190711191110-9a621aea19f8
google.golang.org/appengine v1.6.5 // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/go-playground/validator.v9 v9.28.0
)
Expand Down
Loading

0 comments on commit 2b631de

Please sign in to comment.