Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(deps): rebase the pgx fork onto v5.12.0 and update the replacement (#21840)

renovate[bot]9509fb074663
diff --git a/backend/plugin/db/pg/query_test.go b/backend/plugin/db/pg/query_test.go
index e8a3ed069e..d73e108601 100644
--- a/backend/plugin/db/pg/query_test.go
+++ b/backend/plugin/db/pg/query_test.go
@@ -1,11 +1,15 @@
package pg
import (
+ "context"
"testing"
"time"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/encoding/protojson"
+
+ "github.com/bytebase/bytebase/backend/common/testcontainer"
+ v1pb "github.com/bytebase/bytebase/backend/generated-go/v1"
)
func TestBuildTimestamptzRowValue(t *testing.T) {
@@ -146,3 +150,70 @@ func TestPadZeroes(t *testing.T) {
require.Equal(t, test.expected, got)
}
}
+
+// TestConvertValueTimestampFromDriver reads timestamps through the driver rather than
+// from a constructed time.Time, covering the two behaviors Bytebase's pgx fork adds and
+// upstream does not: timestamptz values arrive in the session time zone, and
+// ColumnType.DecimalSize reports the column's fractional-second scale. A pgx upgrade
+// that loses either patch fails here instead of silently changing query results.
+func TestConvertValueTimestampFromDriver(t *testing.T) {
+ const (
+ sessionZone = "Asia/Shanghai"
+ sessionOffset = 8 * 60 * 60
+ )
+
+ ctx := context.Background()
+ _, db := testcontainer.NewPgDatabase(t)
+
+ // SET applies to one session, so hold a single connection for the query.
+ conn, err := db.Conn(ctx)
+ require.NoError(t, err)
+ defer func() { require.NoError(t, conn.Close()) }()
+ _, err = conn.ExecContext(ctx, "SET TimeZone TO '"+sessionZone+"'")
+ require.NoError(t, err)
+
+ rows, err := conn.QueryContext(ctx, `SELECT
+ '2026-03-04 05:06:07.891234+00'::timestamptz AS tz_default,
+ '2026-03-04 05:06:07.891234+00'::timestamptz(3) AS tz_scale3,
+ '2026-03-04 05:06:07.891234'::timestamp AS ts_default`)
+ require.NoError(t, err)
+ defer rows.Close()
+
+ columnTypes, err := rows.ColumnTypes()
+ require.NoError(t, err)
+ require.Len(t, columnTypes, 3)
+
+ require.True(t, rows.Next())
+ dest := make([]any, len(columnTypes))
+ for i, columnType := range columnTypes {
+ dest[i] = makeValueByTypeName(columnType.DatabaseTypeName(), columnType)
+ }
+ require.NoError(t, rows.Scan(dest...))
+ require.NoError(t, rows.Err())
+
+ values := make(map[string]*v1pb.RowValue, len(columnTypes))
+ for i, columnType := range columnTypes {
+ values[columnType.Name()] = convertValue(columnType.DatabaseTypeName(), columnType, dest[i])
+ }
+
+ tzDefault := values["tz_default"].GetTimestampTzValue()
+ require.NotNil(t, tzDefault)
+ require.Equal(t, "CST", tzDefault.Zone)
+ require.EqualValues(t, sessionOffset, tzDefault.Offset)
+ require.EqualValues(t, 6, tzDefault.Accuracy)
+ require.Equal(t, "2026-03-04T05:06:07.891234Z", tzDefault.GoogleTimestamp.AsTime().Format(time.RFC3339Nano))
+
+ // Postgres rounds the fixture's .891234 to .891 for timestamptz(3).
+ tzScale3 := values["tz_scale3"].GetTimestampTzValue()
+ require.NotNil(t, tzScale3)
+ require.Equal(t, "CST", tzScale3.Zone)
+ require.EqualValues(t, sessionOffset, tzScale3.Offset)
+ require.EqualValues(t, 3, tzScale3.Accuracy)
+ require.Equal(t, "2026-03-04T05:06:07.891Z", tzScale3.GoogleTimestamp.AsTime().Format(time.RFC3339Nano))
+
+ // timestamp without time zone carries no zone, so it is not shifted.
+ tsDefault := values["ts_default"].GetTimestampValue()
+ require.NotNil(t, tsDefault)
+ require.EqualValues(t, 6, tsDefault.Accuracy)
+ require.Equal(t, "2026-03-04T05:06:07.891234Z", tsDefault.GoogleTimestamp.AsTime().Format(time.RFC3339Nano))
+}
diff --git a/go.mod b/go.mod
index ecf91ec4a5..608c2fa38b 100644
--- a/go.mod
+++ b/go.mod
@@ -64,7 +64,7 @@ require (
github.com/hashicorp/vault/api/auth/approle v0.12.0
github.com/jackc/pgconn v1.14.3
github.com/jackc/pgtype v1.14.4
- github.com/jackc/pgx/v5 v5.11.0
+ github.com/jackc/pgx/v5 v5.12.0
github.com/labstack/echo-contrib/v5 v5.0.1
github.com/labstack/echo/v5 v5.4.4
github.com/lib/pq v1.12.3
@@ -378,7 +378,7 @@ replace (
// Other fixes.
github.com/github/gh-ost => github.com/bytebase/gh-ost2 v1.1.7-0.20260512035759-ca2794d6ebea
- github.com/jackc/pgx/v5 => github.com/bytebase/pgx/v5 v5.0.0-20250212161523-96ff8aed8767
+ github.com/jackc/pgx/v5 => github.com/bytebase/pgx/v5 v5.0.0-20261102115508-d3c6cddaeb96
github.com/mattn/go-oci8 => github.com/bytebase/go-obo v0.0.0-20231026081615-705a7fffbfd2
diff --git a/go.sum b/go.sum
index b0c3f5f207..2a7019ab41 100644
--- a/go.sum
+++ b/go.sum
@@ -261,8 +261,8 @@ github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0 h1:bJ8NSf2K+
github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0/go.mod h1:BEWMfiZtqshdmulKJcIsWb45MUaEvDO4CROcgi8dfFg=
github.com/bytebase/omni v0.0.0-20261102094319-61f070707dc7 h1:3rwQ9dpUCGv19YJJfxUivF9ZwiFFa0QCMLBr/YRP+Jc=
github.com/bytebase/omni v0.0.0-20261102094319-61f070707dc7/go.mod h1:9XZE1hqtvr09Oc+DdLu1/yCb8MDcoy/EPdA4AONDHlE=
-github.com/bytebase/pgx/v5 v5.0.0-20250212161523-96ff8aed8767 h1:YuR5G3LcxpO5ScSTA+Kdirxg9RW4TRc/v1t7N2Hfmbw=
-github.com/bytebase/pgx/v5 v5.0.0-20250212161523-96ff8aed8767/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=
+github.com/bytebase/pgx/v5 v5.0.0-20261102115508-d3c6cddaeb96 h1:EOJqbnpc7OG3IzMDM8uO9C0NHFD4TbGtxRpDqh8V/Xs=
+github.com/bytebase/pgx/v5 v5.0.0-20261102115508-d3c6cddaeb96/go.mod h1:u2Fi6no03HCSBYE+ZVdLxbwdu3xyi2vU+K/YNJioSds=
github.com/bytebase/pkcs8 v0.0.0-20240612095628-fcd0a7484c94 h1:6PNsuNmSqCuR8Z616uQLzDIvujWCFsKzeVc3ECmVubk=
github.com/bytebase/pkcs8 v0.0.0-20240612095628-fcd0a7484c94/go.mod h1:SQliXeA7Dhkt//vS29v3zpbEwoa+zb2Cn5xj5uO4K5U=
github.com/bytebase/tidb v0.0.0-20251104040057-d29df9dd1b3b h1:FIMLXCmledlGHw7NzIT2BGVflB2ZNamudc+QtTNITH0=