Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/client/database/postgres/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strings"
"time"

sdkpg "github.com/cloudquery/cq-provider-sdk/database/postgres"
"github.com/hashicorp/go-hclog"
Expand Down Expand Up @@ -36,6 +37,10 @@ func (e Executor) Validate(ctx context.Context) (bool, error) {
return false, err
}

if err := ValidatePostgresConnection(ctx, pool); err != nil {
return false, err
}

if err := ValidatePostgresVersion(ctx, pool, MinPostgresVersion); err != nil {
return true, err
}
Expand All @@ -51,6 +56,14 @@ func (e Executor) Finalize(_ context.Context, err error) error {
return err
}

// ValidatePostgresConnection validates that we can actually connect to the postgres database.
func ValidatePostgresConnection(ctx context.Context, pool *pgxpool.Pool) error {
ctx, cancel := context.WithTimeout(ctx, time.Second*10)
defer cancel()

return pool.Ping(ctx)
}

// queryRower helps with unit tests
type queryRower interface {
QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
Expand Down
4 changes: 4 additions & 0 deletions pkg/client/database/timescale/timescale.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func (e Executor) Validate(ctx context.Context) (bool, error) {
}
defer pool.Close()

if err := postgres.ValidatePostgresConnection(ctx, pool); err != nil {
return false, err
}

if err := postgres.ValidatePostgresVersion(ctx, pool, postgres.MinPostgresVersion); err != nil {
return false, err
}
Expand Down