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

Allow dgraph migrate with remote mysql server. #4860

Merged
merged 3 commits into from Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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