mirror of
https://github.com/xataio/pgroll.git
synced 2024-09-11 05:45:48 +03:00
Ping after creating connection (#195)
Ping the database after establishing a connection for better error messages. Without this change, an error establishing a connection would be prefixed with the message from the next failure. **before**: ``` Error: unable to set pgroll.internal to true: dial tcp [::1]:7432: connect: connection refused ``` **after**: ``` Error: dial tcp [::1]:7432: connect: connection refused ``` Fixes https://github.com/xataio/pgroll/issues/133
This commit is contained in:
parent
3023c0e365
commit
2429a6be6e
@ -39,6 +39,10 @@ func New(ctx context.Context, pgURL, schema string, lockTimeoutMs int, state *st
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := conn.PingContext(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err = conn.ExecContext(ctx, "SET LOCAL pgroll.internal to 'TRUE'")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to set pgroll.internal to true: %w", err)
|
||||
|
@ -225,6 +225,10 @@ func New(ctx context.Context, pgURL, stateSchema string) (*State, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := conn.PingContext(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, err = conn.ExecContext(ctx, "SET LOCAL pgroll.internal to 'TRUE'")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to set pgroll.internal to true: %w", err)
|
||||
|
Loading…
Reference in New Issue
Block a user