Skip to content

sg: properly respect PGUSER/PGDATABASE env vars

Administrator requested to merge sg/fix-sg-pg-vars into main

Created by: slimsag

I encountered issues where sg start was failing to properly migrate by DB schema on startup, and also issues where sg migrate up -db codeintel was incorrectly reporting the DB schema was up-to-date.

https://sourcegraph.slack.com/archives/C01N83PS4TU/p1633379941267400

The cause turned out to be that my PGUSER and PGDATABASE were not being respected, and so it was migrating the wrong DB.

I found that migration.go reproduced some code to build a postgres DSN somewhat incorrectly, we already have a more correct implementation in internal/database/dbutil. It's not possible to merely import it here, since dev/sg is a separate Go module - and I think copying it is not bad given it is simple so I've merely copied it into the package.

Signed-off-by: Stephen Gutekanst [email protected]

Merge request reports

Loading