praefect: Fail sql-migrate when planning migrations errors

What does this MR do and why?

praefect sql-migrate discarded the error from PlanMigration. A failed plan returns a nil slice, which the command could not tell apart from "nothing to do", so a database it could not read, or a recorded migration it did not know about without -ignore-unknown, printed all migrations are up and exited 0. gitlab-ctl reconfigure trusted the exit code and Praefect then crash-looped against a schema missing the new tables.

This MR returns the planning error, wrapped as praefect sql-migrate: plan migrations: ..., so the command exits non-zero with the underlying cause. A test inserts a migration id the binary does not know about and runs without -ignore-unknown, which is the cheapest way to make PlanMigration fail against the test database.

References

Differences

Before: praefect sql-migrate against an unreadable database prints praefect sql-migrate: all migrations are up and exits 0.

After: It prints praefect sql-migrate: plan migrations: <cause> to stderr and exits 1.

How to set up and validate locally

  1. Point config.toml at a database with wrong credentials.
  2. Run praefect -config config.toml sql-migrate; the exit code is 1 and the error names the connection failure.
  3. go test ./internal/cli/praefect/ -run TestSubCmdSqlMigrate (needs the test Postgres).
Edited by Jeston Singh

Merge request reports

Loading
Loading