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.

(cherry picked from commit 9bed827)
  • Loading branch information
Arijit Das authored and danielmai committed Mar 19, 2020
1 parent 63957f9 commit e54a02c
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
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
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 e54a02c

Please sign in to comment.