From 7978f29e498750082a7feac9d799aeb0e71eaa09 Mon Sep 17 00:00:00 2001 From: William Batista Date: Mon, 25 Mar 2024 10:24:50 -0400 Subject: [PATCH] Connect to a specific machine when importing We previously had a bug where, due to the fact that we weren't skipping DNS registration, `fly pg import` would create a machine that tried to import from itself, obviously failing. Although the DNS registration bug is [being fixed](https://github.com/superfly/fly-proxy/pull/1192), I still think that relying on skipping DNS registration is a little silly, when we can just guarantee we'll connect to the correct machine using 6PN wizardry. `flyctl` needs to specify a machine ID to connect to which, as of writing, is just any working machine in the app we want to import into. --- cmd/migrate/main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/migrate/main.go b/cmd/migrate/main.go index 4559912..dad9696 100644 --- a/cmd/migrate/main.go +++ b/cmd/migrate/main.go @@ -55,8 +55,16 @@ func main() { os.Exit(1) return } + machineID := os.Getenv("PG_MACHINE_ID") - targetURI := fmt.Sprintf("postgres://postgres:%s@%s.internal:5432", operatorPass, appName) + appDomain := appName + ".internal" + if machineID != "" { + appDomain = machineID + ".vm." + appDomain + } else { + log.Println("[warn] PG_MACHINE_ID was not specified, falling back to resolving from app name") + } + + targetURI := fmt.Sprintf("postgres://postgres:%s@%s:5432", operatorPass, appDomain) opts := migrationOpts{ sourceURI: sourceURI,