Skip to content

Commit

Permalink
Connect to a specific machine when importing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
billyb2 committed Mar 25, 2024
1 parent 689cc4c commit 7978f29
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cmd/migrate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7978f29

Please # to comment.