Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] pgx v5 #25

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 4 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ version: 2.1
orbs:
codecov: codecov/[email protected]
ucheck: udacity/ucheck@1
go: circleci/[email protected]

executors:
go:
docker:
- image: cimg/go:1.18
- image: cimg/go:1.21
vm:
machine:
image: ubuntu-2004:202111-02
Expand All @@ -23,6 +24,8 @@ jobs:
executor: vm
steps:
- checkout
- go/install:
version: "1.21.3"
- run:
name: Run tests
command: make test
Expand Down
8 changes: 7 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
linters:
enable-all: true
disable:
- typecheck
- deadcode # deprecated
- golint # deprecated
- ifshort # deprecated
- interfacer # deprecated
- maligned # deprecated
- nosnakecase # deprecated
- scopelint # deprecated
- structcheck # deprecated
- varcheck # deprecated
- depguard
- exhaustivestruct
- exhaustruct
- gochecknoglobals
- gochecknoinits
- paralleltest
- typecheck
- cyclop # todo
- errorlint # todo
- funlen # todo
Expand Down
2 changes: 1 addition & 1 deletion cmd/pgverify/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v5"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type Config struct {

// Option interface used for setting optional config properties.
type Option interface {
apply(*Config)
apply(c *Config)
}

type optionFunc func(*Config)
Expand Down
229 changes: 122 additions & 107 deletions go.mod

Large diffs are not rendered by default.

993 changes: 308 additions & 685 deletions go.sum

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"github.com/cjfinnell/pgverify"
"github.com/google/uuid"
"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v5"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -68,8 +68,8 @@ func createContainer(t *testing.T, ctx context.Context, image string, port int,
image: image,
ports: []*portMapping{
{
HostPort: fmt.Sprintf("%d", hostPort),
ContainerPort: fmt.Sprintf("%d", port),
HostPort: strconv.Itoa(hostPort),
ContainerPort: strconv.Itoa(port),
},
},
env: env,
Expand Down Expand Up @@ -261,9 +261,9 @@ func TestVerifyData(t *testing.T) {
aliases = append(aliases, db.image)
// Create db and connect
_, port, err := createContainer(t, ctx, db.image, db.port, db.env, db.cmd)
assert.NoError(t, err)
require.NoError(t, err)
config, err := pgx.ParseConfig(fmt.Sprintf("postgresql://%[email protected]:%d%s", db.userPassword, port, db.db))
assert.NoError(t, err)
require.NoError(t, err)
assert.True(t, waitForDBReady(t, ctx, config))
conn, err := pgx.ConnectConfig(ctx, config)
require.NoError(t, err)
Expand All @@ -274,7 +274,7 @@ func TestVerifyData(t *testing.T) {
for _, tableName := range tableNames {
createTableQuery := fmt.Sprintf(`CREATE TABLE "%s" %s`, tableName, createTableQueryBase)
_, err = conn.Exec(ctx, createTableQuery)
assert.NoError(t, err, "Failed to create table %s on %v with query: %s", tableName, db.image, createTableQuery)
require.NoError(t, err, "Failed to create table %s on %v with query: %s", tableName, db.image, createTableQuery)

pkeyString := fmt.Sprintf("single_col_pkey_%s PRIMARY KEY (id)", tableName)
if tableName == tableNames[1] {
Expand All @@ -283,12 +283,12 @@ func TestVerifyData(t *testing.T) {

alterTableQuery := fmt.Sprintf(`ALTER TABLE ONLY "%s" ADD CONSTRAINT %s;`, tableName, pkeyString)
_, err = conn.Exec(ctx, alterTableQuery)
assert.NoError(t, err, "Failed to add primary key to table %s on %v with query %s", tableName, db.image, alterTableQuery)
require.NoError(t, err, "Failed to add primary key to table %s on %v with query %s", tableName, db.image, alterTableQuery)

rand.Shuffle(len(valueClauses), func(i, j int) { valueClauses[i], valueClauses[j] = valueClauses[j], valueClauses[i] })
insertDataQuery := fmt.Sprintf(`INSERT INTO "%s" %s %s`, tableName, insertDataQueryBase, strings.Join(valueClauses, ", "))
_, err = conn.Exec(ctx, insertDataQuery)
assert.NoError(t, err, "Failed to insert data to table on %v with query %s", tableName, db.image, insertDataQuery)
require.NoError(t, err, "Failed to insert data to table on %v with query %s", tableName, db.image, insertDataQuery)
}

targets = append(targets, config)
Expand All @@ -313,7 +313,7 @@ func TestVerifyData(t *testing.T) {
pgverify.WithAliases(aliases),
pgverify.WithBookendLimit(5),
)
assert.NoError(t, err)
require.NoError(t, err)
results.WriteAsTable(os.Stdout)
}
}
20 changes: 17 additions & 3 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,35 @@
import (
"context"

"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v5/tracelog"
"github.com/sirupsen/logrus"
)

var _ pgx.Logger = (*pgxLogger)(nil)
var _ tracelog.Logger = (*pgxLogger)(nil)

type pgxLogger struct {
l logrus.FieldLogger
}

func (p *pgxLogger) Log(ctx context.Context, level pgx.LogLevel, msg string, data map[string]interface{}) {
func (p *pgxLogger) Log(ctx context.Context, level tracelog.LogLevel, msg string, data map[string]interface{}) {

Check warning on line 16 in log.go

View check run for this annotation

Codecov / codecov/patch

log.go#L16

Added line #L16 was not covered by tests
parsedLevel, err := logrus.ParseLevel(level.String())
if err != nil {
parsedLevel = logrus.ErrorLevel
}

p.l.WithFields(data).Log(parsedLevel, msg)
}

func NewTraceLogger(l *logrus.Entry) *tracelog.TraceLog {
logLevel, err := tracelog.LogLevelFromString(l.Level.String())
if err != nil {
l.WithError(err).Warn("failed to parse log level, defaulting to error")

logLevel = tracelog.LogLevelError
}

return &tracelog.TraceLog{
Logger: &pgxLogger{l},
LogLevel: logLevel,
}
}
21 changes: 21 additions & 0 deletions vendor/4d63.com/gocheckcompilerdirectives/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading