Skip to content

Commit 2e63463

Browse files
authored
upgrade dependencies, tests and service versions
* set number of test jobs based on available cores * upgrade dependencies and service versions * use testify in all tests * add go1.22 * add missing ContextKey * formatting * update dependencies
1 parent 1d0115f commit 2e63463

Some content is hidden

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

60 files changed

+919
-1174
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
os: [ubuntu-latest]
16-
go-version: [1.19.x, 1.20.x, 1.21.x]
16+
go-version: [1.20.x, 1.21.x, 1.22.x]
1717

1818
runs-on: ${{ matrix.os }}
1919

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
SHELL ?= /bin/bash
1+
SHELL ?= bash
2+
CPU_CORES ?= $(shell nproc)
23

3-
PARALLEL_FLAGS ?= --halt-on-error 2 --jobs=2 -v -u
4+
PARALLEL_FLAGS ?= --halt-on-error 2 --jobs=$(CPU_CORES) -v -u
45

5-
TEST_FLAGS ?=
6+
TEST_FLAGS ?= -v -failfast -race -timeout 20m
67

78
UPPER_DB_LOG ?= WARN
89

adapter/cockroachdb/Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
SHELL ?= bash
22

3-
COCKROACHDB_VERSION ?= v23.1.8
4-
COCKROACHDB_SUPPORTED ?= $(COCKROACHDB_VERSION) v22.2.9 v21.2.9
5-
PROJECT ?= upper_cockroachdb_$(COCKROACHDB_VERSION)
3+
COCKROACHDB_VERSION ?= v23.2.6
4+
COCKROACHDB_SUPPORTED ?= $(COCKROACHDB_VERSION) v22.2.19 v21.2.17
5+
PROJECT ?= $(subst .,_,"upper_cockroachdb_$(COCKROACHDB_VERSION)")
66

77
DB_HOST ?= 127.0.0.1
88
DB_PORT ?= 26257
@@ -30,7 +30,7 @@ test-no-race:
3030
go test -v -failfast $(TEST_FLAGS)
3131

3232
server-up: server-down
33-
docker-compose -p $(PROJECT) up -d && \
33+
docker compose -p $(PROJECT) up -d && \
3434
sleep 5 && \
3535
psql -Uroot -h$(DB_HOST) -p$(DB_PORT) postgres -c "\
3636
DROP USER IF EXISTS $(DB_USERNAME); \
@@ -41,7 +41,7 @@ server-up: server-down
4141
"
4242

4343
server-down:
44-
docker-compose -p $(PROJECT) down
44+
docker compose -p $(PROJECT) down
4545

4646
test-extended:
4747
parallel $(PARALLEL_FLAGS) \

adapter/cockroachdb/connection.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ func (vs values) Isset(k string) bool {
7575
//
7676
// You can use a ConnectionURL struct as an argument for Open:
7777
//
78-
// var settings = cockroachdb.ConnectionURL{
79-
// Host: "localhost", // Database server IP or host name.
80-
// Database: "peanuts", // Database name.
81-
// User: "cbrown", // Optional user name.
82-
// Password: "snoopy", // Optional user password.
83-
// }
78+
// var settings = cockroachdb.ConnectionURL{
79+
// Host: "localhost", // Database server IP or host name.
80+
// Database: "peanuts", // Database name.
81+
// User: "cbrown", // Optional user name.
82+
// Password: "snoopy", // Optional user password.
83+
// }
8484
//
85-
// sess, err = cockroachdb.Open(settings)
85+
// sess, err = cockroachdb.Open(settings)
8686
//
8787
// If you already have a valid DSN, you can use ParseURL to convert it into
8888
// a ConnectionURL before passing it to Open.

adapter/cockroachdb/custom_types.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"database/sql/driver"
2828
"time"
2929

30+
"github.com/upper/db/v4"
3031
"github.com/upper/db/v4/internal/sqlbuilder"
3132
)
3233

@@ -90,12 +91,12 @@ func DecodeJSONB(dst interface{}, src interface{}) error {
9091
//
9192
// Example:
9293
//
93-
// type MyCustomStruct struct {
94-
// ID int64 `db:"id" json:"id"`
95-
// Name string `db:"name" json:"name"`
96-
// ...
97-
// cockroachdb.JSONBConverter
98-
// }
94+
// type MyCustomStruct struct {
95+
// ID int64 `db:"id" json:"id"`
96+
// Name string `db:"name" json:"name"`
97+
// ...
98+
// cockroachdb.JSONBConverter
99+
// }
99100
type JSONBConverter struct {
100101
}
101102

@@ -144,7 +145,7 @@ func (t *timeWrapper) Scan(src interface{}) error {
144145
}
145146

146147
func (d *database) ConvertValueContext(ctx context.Context, in interface{}) interface{} {
147-
tz, _ := ctx.Value("timezone").(*time.Location)
148+
tz, _ := ctx.Value(db.ContextKey("timezone")).(*time.Location)
148149

149150
switch v := in.(type) {
150151
case *time.Time:

adapter/cockroachdb/custom_types_pgx.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !pq
12
// +build !pq
23

34
// Copyright (c) 2012-present The upper.io/db authors. All rights reserved.

adapter/cockroachdb/custom_types_pq.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build pq
12
// +build pq
23

34
// Copyright (c) 2012-present The upper.io/db authors. All rights reserved.

adapter/cockroachdb/database_pgx.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !pq
12
// +build !pq
23

34
// Copyright (c) 2012-present The upper.io/db authors. All rights reserved.
@@ -26,9 +27,12 @@ package cockroachdb
2627
import (
2728
"context"
2829
"database/sql"
30+
31+
"time"
32+
2933
_ "github.com/jackc/pgx/v4/stdlib"
34+
"github.com/upper/db/v4"
3035
"github.com/upper/db/v4/internal/sqladapter"
31-
"time"
3236
)
3337

3438
func (*database) OpenDSN(sess sqladapter.Session, dsn string) (*sql.DB, error) {
@@ -38,7 +42,7 @@ func (*database) OpenDSN(sess sqladapter.Session, dsn string) (*sql.DB, error) {
3842
}
3943
if tz := connURL.Options["timezone"]; tz != "" {
4044
loc, _ := time.LoadLocation(tz)
41-
ctx := context.WithValue(sess.Context(), "timezone", loc)
45+
ctx := context.WithValue(sess.Context(), db.ContextKey("timezone"), loc)
4246
sess.SetContext(ctx)
4347
}
4448
return sql.Open("pgx", dsn)

adapter/cockroachdb/database_pq.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build pq
12
// +build pq
23

34
// Copyright (c) 2012-present The upper.io/db authors. All rights reserved.
@@ -26,9 +27,11 @@ package cockroachdb
2627
import (
2728
"context"
2829
"database/sql"
30+
"time"
31+
2932
_ "github.com/lib/pq"
33+
db "github.com/upper/db/v4"
3034
"github.com/upper/db/v4/internal/sqladapter"
31-
"time"
3235
)
3336

3437
func (*database) OpenDSN(sess sqladapter.Session, dsn string) (*sql.DB, error) {
@@ -38,7 +41,7 @@ func (*database) OpenDSN(sess sqladapter.Session, dsn string) (*sql.DB, error) {
3841
}
3942
if tz := connURL.Options["timezone"]; tz != "" {
4043
loc, _ := time.LoadLocation(tz)
41-
ctx := context.WithValue(sess.Context(), "timezone", loc)
44+
ctx := context.WithValue(sess.Context(), db.ContextKey("timezone"), loc)
4245
sess.SetContext(ctx)
4346
}
4447
return sql.Open("postgres", dsn)

adapter/cockroachdb/docker-compose.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
version: '3'
2-
31
services:
4-
52
server:
63
image: cockroachdb/cockroach:${COCKROACHDB_VERSION:-v2}
74
environment:

0 commit comments

Comments
 (0)