sourcegraph/lib/errors/postgres.go
Noah S-C e13606a86f
migrator: exit 0 if autoupgrade set on up (#53175)
When auto-upgrade intent is signaled, we want the frontend to do the
migration instead of migrator. As by default, migrator runs up (unless
manually changed to something else or invoked), we check before that
command runs whether we should auto-upgrade, and exiting with 0 if yes

## Test plan

Tested locally in docker-compose setup
2023-06-13 20:51:09 +00:00

13 lines
302 B
Go

package errors
import (
"github.com/jackc/pgconn"
)
// HasPostgresCode checks whether any of the errors in the chain
// signify a postgres error with the given error code.
func HasPostgresCode(err error, code string) bool {
var pgerr *pgconn.PgError
return As(err, &pgerr) && pgerr.Code == code
}