Skip to content

Commit

Permalink
Allow dgraph migrate with remote mysql server. (#4860)
Browse files Browse the repository at this point in the history
* Allow dgraph migrate with remote mysql server.

* Minor change.

* Minor changes.
  • Loading branch information
Arijit Das authored Mar 2, 2020
1 parent 62856d1 commit 9bed827
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion dgraph/cmd/migrate/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func init() {
flag.StringP("output_data", "o", "sql.rdf", "The data output file")
flag.StringP("separator", "p", ".", "The separator for constructing predicate names")
flag.BoolP("quiet", "q", false, "Enable quiet mode to suppress the warning logs")
flag.StringP("host", "", "localhost", "The hostname or IP address of the database server.")
flag.StringP("port", "", "3306", "The port of the database server.")
}

func run(conf *viper.Viper) error {
Expand All @@ -67,6 +69,8 @@ func run(conf *viper.Viper) error {
tables := conf.GetString("tables")
schemaOutput := conf.GetString("output_schema")
dataOutput := conf.GetString("output_data")
host := conf.GetString("host")
port := conf.GetString("port")
quiet = conf.GetBool("quiet")
separator = conf.GetString("separator")

Expand All @@ -93,7 +97,7 @@ func run(conf *viper.Viper) error {

initDataTypes()

pool, err := getPool(user, db, password)
pool, err := getPool(host, port, user, password, db)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions dgraph/cmd/migrate/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import (
"github.com/pkg/errors"
)

func getPool(user string, db string, password string) (*sql.DB,
func getPool(host, port, user, password, db string) (*sql.DB,
error) {
return sql.Open("mysql",
fmt.Sprintf("%s:%s@/%s?parseTime=true", user, password, db))
fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?parseTime=true", user, password, host, port, db))
}

// showTables will return a slice of table names using one of the following logic
Expand Down

0 comments on commit 9bed827

Please sign in to comment.