Skip to content

fix(migrate): show the connected database and DSN source - #347

Open
rayw-lab wants to merge 1 commit into
skudra-go:mainfrom
rayw-lab:fix/342
Open

rayw-lab wants to merge 1 commit into
skudra-go:mainfrom
rayw-lab:fix/342

Conversation

@rayw-lab

@rayw-lab rayw-lab commented Nov 26, 2026 •

Copy link
Copy Markdown

Two PostgreSQL servers can have a database with the same name. The commands up, status, baseline, repair, and seed now print the address they reached, the database name, and which setting supplied the connection string. That makes it easier to spot when the CLI and the app are talking to different servers.

The notice comes from the open connection and uses only those three values. Connection settings still take priority in the order of the flag, the environment variable, and the app config. up --dry-run keeps its existing SQL output.

I tried this on two local PostgreSQL 17 servers with the same database name. A URL connection and a keyword connection with a fallback host each showed the port the CLI actually reached.

make fmt, make lint, make test, and make test-pg passed locally. The documentation example checker flags the same spacing in the Raw example on main and on this branch.

Refs #342.

After release

Update migrations/commands and migrations/deploying in ant-docs.

@rayw-lab

Copy link
Copy Markdown
Author

I rebased this on main and regenerated the decision index to resolve the conflict. go test ./tests/docs ./tests/api ./migrate passes locally.

@borderss

Copy link
Copy Markdown
Contributor

Thanks for the rebase. A few things before this can go in:

  1. Decision 168 is already taken. feat(ids): add UUIDv7, a version 7 UUID of any 16-byte type #346 adds docs/decisions/168-ids-uuidv7-makes-a-uuid-of-any-16-byte-type.md and goes in first. Numbers up to 176 are used on main or by open PRs, so rename yours to 177-the-migrate-commands-name-their-database.md, set id: 177 and the heading, and rerun go test ./tests/docs -update.

  2. The name alone can't tell two servers apart. migrate up doesn't say which database it changes, and DATABASE_URL beats the program's own DSN #342 proposes printing the target with the password removed (postgres@localhost:5433/playground-db). current_database() gives the same answer for postgres on localhost:5432 and on localhost:5433, or for app on staging and on production, and that is the mix-up the issue is about. The source label helps, but it doesn't settle it. Host and port aren't secret the way a password is. If you leave them out on purpose, record that as a rejected option in the decision with the reason, since the issue asked for them. If you add them, parse both DSN forms (URL and key=value) and drop the password and any other credential parameter.

  3. Unrelated hunk in skills/ant/SKILL.md:292. It re-aligns the // *int comment of the Raw sample. Please drop it.

  4. Nit, migrate/cli.go:266. The condition is spread over three lines, which hides the &&/|| precedence. command == "up" && !dry || slices.Contains([]string{"status", "baseline", "repair", "seed"}, command) reads in one go.

@rayw-lab

Copy link
Copy Markdown
Author

Thanks for the two-port example. I rebased on main, moved the decision to 177, rebuilt the index, and dropped the unrelated formatting change.

The notice now shows the server address as well as the database name and connection source. I ran the CLI against two PostgreSQL 17 servers with the same database name. The URL and keyword connections printed different ports, including the port reached after a fallback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants