From 9bed827cee2fba277e6777f2b0dff96fca1e0894 Mon Sep 17 00:00:00 2001 From: Arijit Das Date: Mon, 2 Mar 2020 13:20:53 +0530 Subject: [PATCH] Allow dgraph migrate with remote mysql server. (#4860) * Allow dgraph migrate with remote mysql server. * Minor change. * Minor changes. --- dgraph/cmd/migrate/run.go | 6 +++++- dgraph/cmd/migrate/utils.go | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/dgraph/cmd/migrate/run.go b/dgraph/cmd/migrate/run.go index 3d0128295f1..4a498a83238 100644 --- a/dgraph/cmd/migrate/run.go +++ b/dgraph/cmd/migrate/run.go @@ -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 { @@ -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") @@ -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 } diff --git a/dgraph/cmd/migrate/utils.go b/dgraph/cmd/migrate/utils.go index cccaa33427b..4d03ae77ac5 100644 --- a/dgraph/cmd/migrate/utils.go +++ b/dgraph/cmd/migrate/utils.go @@ -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