Skip to content

Commit 674d0f9

Browse files
committed
chore: upgrade from pgx v4 to v5
In July 2025 v4 will reach end of life. This change updates claircore to use v5. Signed-off-by: crozzy <[email protected]>
1 parent 49f1591 commit 674d0f9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+919
-161
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ jobs:
108108
cd "$dir"
109109
go list -m
110110
go mod download
111-
go test -race ${RUNNER_DEBUG:+-v} "-coverprofile=${{ runner.temp }}/$(go list -m | tr / _).codecov.out" -covermode=atomic ./...
111+
GOMAXPROCS=2 go test -race ${RUNNER_DEBUG:+-v} "-coverprofile=${{ runner.temp }}/$(go list -m | tr / _).codecov.out" -covermode=atomic ./...
112112
); done
113113
- name: Codecov
114114
if: >-

datastore/postgres/affected_manifests_e2e_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import (
77
"path/filepath"
88
"testing"
99

10-
"github.com/jackc/pgtype"
11-
"github.com/jackc/pgx/v4/pgxpool"
10+
"github.com/jackc/pgx/v5/pgxpool"
1211
"github.com/quay/zlog"
1312

1413
"github.com/quay/claircore"
@@ -194,15 +193,12 @@ func (e *affectedE2E) IndexArtifacts(t *testing.T) {
194193
t.Fatalf("failed to insert manifest: %v", err)
195194
}
196195
for _, pkg := range e.ir.Packages {
197-
var nVer pgtype.Int4Array
198-
nVer.Status = pgtype.Present
199-
nVer.Set(pkg.NormalizedVersion.V)
200196
_, err := e.pool.Exec(ctx, insertPkg,
201197
pkg.Name,
202198
pkg.Kind,
203199
pkg.Version,
204200
pkg.NormalizedVersion.Kind,
205-
&nVer,
201+
pkg.NormalizedVersion,
206202
pkg.Module,
207203
pkg.Arch,
208204
pkg.ID,
@@ -212,13 +208,12 @@ func (e *affectedE2E) IndexArtifacts(t *testing.T) {
212208
}
213209
if pkg.Source != nil {
214210
pkg := pkg.Source
215-
nVer.Set(pkg.NormalizedVersion.V)
216211
_, err := e.pool.Exec(ctx, insertPkg,
217212
pkg.Name,
218213
pkg.Kind,
219214
pkg.Version,
220215
pkg.NormalizedVersion.Kind,
221-
&nVer,
216+
pkg.NormalizedVersion,
222217
pkg.Module,
223218
pkg.Arch,
224219
pkg.ID,

datastore/postgres/affectedmanifest.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"time"
99

1010
"github.com/jackc/pgtype"
11-
"github.com/jackc/pgx/v4"
12-
"github.com/jackc/pgx/v4/pgxpool"
11+
"github.com/jackc/pgx/v5"
12+
"github.com/jackc/pgx/v5/pgxpool"
1313
"github.com/prometheus/client_golang/prometheus"
1414
"github.com/prometheus/client_golang/prometheus/promauto"
1515
"github.com/quay/zlog"
@@ -143,15 +143,13 @@ WHERE
143143
for rows.Next() {
144144
var pkg claircore.Package
145145
var id int64
146-
var nKind *string
147-
var nVer pgtype.Int4Array
148146
err := rows.Scan(
149147
&id,
150148
&pkg.Name,
151149
&pkg.Version,
152150
&pkg.Kind,
153-
&nKind,
154-
&nVer,
151+
&pkg.NormalizedVersion.Kind,
152+
&pkg.NormalizedVersion,
155153
&pkg.Module,
156154
&pkg.Arch,
157155
)
@@ -160,12 +158,6 @@ WHERE
160158
}
161159
idStr := strconv.FormatInt(id, 10)
162160
pkg.ID = idStr
163-
if nKind != nil {
164-
pkg.NormalizedVersion.Kind = *nKind
165-
for i, n := range nVer.Elements {
166-
pkg.NormalizedVersion.V[i] = n.Int
167-
}
168-
}
169161
pkgsToFilter = append(pkgsToFilter, pkg)
170162
}
171163
zlog.Debug(ctx).Int("count", len(pkgsToFilter)).Msg("packages to filter")

datastore/postgres/connect.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/jackc/pgx/v4/pgxpool"
7+
"github.com/jackc/pgx/v5/pgxpool"
88
"github.com/prometheus/client_golang/prometheus"
99
"github.com/quay/zlog"
1010

11+
"github.com/quay/claircore/datastore/postgres/types"
1112
"github.com/quay/claircore/pkg/poolstats"
1213
)
1314

@@ -24,8 +25,9 @@ func Connect(ctx context.Context, connString string, applicationName string) (*p
2425
if _, ok := params[appnameKey]; !ok {
2526
params[appnameKey] = applicationName
2627
}
28+
cfg.AfterConnect = types.ConnectRegisterTypes
2729

28-
pool, err := pgxpool.ConnectConfig(ctx, cfg)
30+
pool, err := pgxpool.NewWithConfig(ctx, cfg)
2931
if err != nil {
3032
return nil, fmt.Errorf("failed to create ConnPool: %v", err)
3133
}

datastore/postgres/deletemanifests.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"errors"
66
"fmt"
77

8-
"github.com/jackc/pgx/v4"
8+
"github.com/jackc/pgx/v5"
99
"github.com/prometheus/client_golang/prometheus"
1010
"github.com/prometheus/client_golang/prometheus/promauto"
1111
"github.com/quay/zlog"
@@ -62,7 +62,7 @@ func (s *IndexerStore) DeleteManifests(ctx context.Context, ds ...claircore.Dige
6262
}(&err)
6363
deletedManifests := make([]claircore.Digest, 0, len(ds))
6464
for _, d := range ds {
65-
s.pool.BeginFunc(ctx, func(tx pgx.Tx) error {
65+
pgx.BeginFunc(ctx, s.pool, func(tx pgx.Tx) error {
6666
defer promTimer(deleteManifestsDuration, "deleteLayers", &err)()
6767
defer func(e *error) {
6868
deleteManifestsCounter.WithLabelValues("deleteLayers", success(*e)).Inc()

datastore/postgres/distributionsbylayer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"strconv"
88
"time"
99

10-
"github.com/jackc/pgx/v4"
10+
"github.com/jackc/pgx/v5"
1111
"github.com/prometheus/client_golang/prometheus"
1212
"github.com/prometheus/client_golang/prometheus/promauto"
1313

datastore/postgres/enrichment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
"time"
1212

1313
"github.com/google/uuid"
14-
"github.com/jackc/pgx/v4"
15-
"github.com/jackc/pgx/v4/pgxpool"
14+
"github.com/jackc/pgx/v5"
15+
"github.com/jackc/pgx/v5/pgxpool"
1616
"github.com/prometheus/client_golang/prometheus"
1717
"github.com/prometheus/client_golang/prometheus/promauto"
1818
"github.com/quay/zlog"

datastore/postgres/filesbylayer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"fmt"
77
"time"
88

9-
"github.com/jackc/pgx/v4"
9+
"github.com/jackc/pgx/v5"
1010
"github.com/prometheus/client_golang/prometheus"
1111
"github.com/prometheus/client_golang/prometheus/promauto"
1212

datastore/postgres/gc.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import (
99
"time"
1010

1111
"github.com/google/uuid"
12-
"github.com/jackc/pgtype"
13-
"github.com/jackc/pgx/v4/pgxpool"
12+
"github.com/jackc/pgx/v5/pgxpool"
1413
"github.com/prometheus/client_golang/prometheus"
1514
"github.com/prometheus/client_golang/prometheus/promauto"
1615
"github.com/quay/zlog"
@@ -201,15 +200,12 @@ WHERE array_length(ordered_ops.refs, 1) > $2;
201200

202201
defer rows.Close()
203202
for rows.Next() {
204-
// pgx will not scan directly into a []uuid.UUID
205-
tmp := pgtype.UUIDArray{}
203+
var tmp []uuid.UUID
206204
err := rows.Scan(&tmp)
207205
if err != nil {
208206
return nil, 0, fmt.Errorf("error scanning update operations: %w", err)
209207
}
210-
for _, u := range tmp.Elements {
211-
m = append(m, u.Bytes) // this works since [16]byte value is assignable to uuid.UUID
212-
}
208+
m = append(m, tmp...)
213209
}
214210
if rows.Err() != nil {
215211
return nil, 0, rows.Err()

datastore/postgres/gc_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/quay/claircore"
1515
"github.com/quay/claircore/libvuln/driver"
1616
"github.com/quay/claircore/libvuln/updates"
17-
"github.com/quay/claircore/pkg/ctxlock"
17+
"github.com/quay/claircore/pkg/ctxlock/v2"
1818
"github.com/quay/claircore/test"
1919
"github.com/quay/claircore/test/integration"
2020
pgtest "github.com/quay/claircore/test/postgres"
@@ -181,7 +181,6 @@ func TestGC(t *testing.T) {
181181
t.Fatalf("manager failed to run: %v", err)
182182
}
183183
}
184-
185184
// confirm update operations exist
186185
ops, err := store.GetUpdateOperations(ctx, driver.VulnerabilityKind)
187186
if err != nil {

0 commit comments

Comments
 (0)