Skip to content

Commit 2b90a38

Browse files
authored
Merge pull request #62 from qonto/timestamptz-fix
2 parents 2560486 + c46ae11 commit 2b90a38

File tree

12 files changed

+129
-44
lines changed

12 files changed

+129
-44
lines changed

.github/workflows/linter.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ jobs:
1616
- uses: actions/checkout@v4
1717
- uses: actions/setup-go@v5
1818
with:
19-
go-version: '1.21'
19+
go-version: '1.23'
2020
cache: false
2121
- name: golangci-lint
2222
uses: golangci/golangci-lint-action@v6
2323
with:
24-
version: v1.54
24+
version: v1.61
2525

2626
yamllint:
2727
name: yamllint

.github/workflows/test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- uses: actions/checkout@v4
2020
- uses: actions/setup-go@v5
2121
with:
22-
go-version: '1.21'
22+
go-version: '1.23'
2323
- name: Install dependencies
2424
run: |
2525
go get .
@@ -167,7 +167,7 @@ jobs:
167167
- uses: actions/checkout@v4
168168
- uses: actions/setup-go@v5
169169
with:
170-
go-version: '1.21'
170+
go-version: '1.23'
171171
- name: Install dependencies
172172
run: |
173173
go get .

.golangci.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
---
22
run:
33
concurrency: 4
4-
deadline: 2m
4+
timeout: 2m
55
issues-exit-code: 1
66
tests: true
77

88
output:
9-
format: colored-line-number
9+
formats:
10+
- format: colored-line-number
1011
print-issued-lines: true
1112
print-linter-name: true
1213

@@ -34,11 +35,11 @@ linters:
3435
- gocritic
3536
- gocyclo
3637
- godox
37-
- goerr113
38+
- err113
3839
- gofmt
3940
- gofumpt
4041
- goimports
41-
- gomnd
42+
- mnd
4243
- gomodguard
4344
- goprintffuncname
4445
- gosec
@@ -81,8 +82,8 @@ linters-settings:
8182

8283
issues:
8384
exclude-use-default: false
84-
max-per-linter: 1024
85-
max-same: 1024
85+
max-issues-per-linter: 1024
86+
max-same-issues: 1024
8687

8788
exclude-rules:
8889
# Exclude some linters from running on test files

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repos:
1111
- id: detect-private-key
1212
- id: check-symlinks
1313
- repo: https://github.com/golangci/golangci-lint
14-
rev: v1.54.2
14+
rev: v1.61.0
1515
hooks:
1616
- id: golangci-lint
1717
- repo: https://github.com/Bahjat/pre-commit-golang

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@ PPM will process all referenced partitions and exit with a non-zero code if it d
2121

2222
- Support of PostgreSQL 14+
2323
- Only supports [`RANGE` partition strategy](https://www.postgresql.org/docs/current/ddl-partitioning.html#DDL-PARTITIONING-OVERVIEW-RANGE)
24-
- The partition key must be a column of `date`, `timestamp`, or `uuid` type
24+
- Gaps are not allowed in-between partitions
25+
- The partition key must be a column of `date`, `timestamp`, `timestamptz` or `uuid` type
2526
- Support `daily`, `weekly`, `monthly`, `quarterly`, and `yearly` partitioning
26-
- Dates are implemented through UTC timezone
27-
- Partition names are enforced and not configurable
27+
- Partition names are not configurable
2828

2929
| Partition interval | Pattern | Example |
3030
| ------------------ | ----------------------------------------- | ----------------- |
3131
| daily | `<parent_table>_<YYYY>_<DD>_<MM>` | `logs_2024_06_25` |
32-
| weekly | `<parent_table>_w<week number>` | `logs_2024_w26` |
32+
| weekly | `<parent_table>_w<ISO week number>` | `logs_2024_w26` |
3333
| quarterly | `<parent_table>_<YYYY>_q<quarter number>` | `logs_2024_q1` |
3434
| monthly | `<parent_table>_<YYYY>_<MM>` | `logs_2024_06` |
3535
| yearly | `<parent_table>_<YYYY>` | `logs_2024` |
3636

37+
Whenever that interval is changed in the configuration, the provisioning may create new partitions shorter than the interval and named `<parent_table>_<YYYYDDMM>_<YYYYDDMM>` to fill the gaps between the existing and new partitions. These gaps can range from one day to the new interval size minus one day.
38+
3739
## Installation
3840

3941
PPM is available as a Docker image, Debian package, and Binary.

go.mod

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module github.com/qonto/postgresql-partition-manager
22

3-
go 1.21.3
3+
go 1.23.0
44

5-
toolchain go1.21.9
5+
toolchain go1.23.2
66

77
require (
88
github.com/go-playground/validator/v10 v10.22.0
99
github.com/google/uuid v1.6.0
1010
github.com/jackc/pgconn v1.14.3
11-
github.com/jackc/pgx/v5 v5.6.0
11+
github.com/jackc/pgx/v5 v5.7.5
1212
github.com/pashagolub/pgxmock/v3 v3.4.0
1313
github.com/spf13/cobra v1.8.1
1414
github.com/spf13/viper v1.19.0
@@ -29,8 +29,8 @@ require (
2929
github.com/jackc/pgio v1.0.0 // indirect
3030
github.com/jackc/pgpassfile v1.0.0 // indirect
3131
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
32-
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
33-
github.com/jackc/puddle/v2 v2.2.1 // indirect
32+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
33+
github.com/jackc/puddle/v2 v2.2.2 // indirect
3434
github.com/leodido/go-urn v1.4.0 // indirect
3535
github.com/magiconair/properties v1.8.7 // indirect
3636
github.com/mitchellh/mapstructure v1.5.0 // indirect
@@ -47,12 +47,12 @@ require (
4747
github.com/subosito/gotenv v1.6.0 // indirect
4848
go.uber.org/atomic v1.9.0 // indirect
4949
go.uber.org/multierr v1.9.0 // indirect
50-
golang.org/x/crypto v0.21.0 // indirect
50+
golang.org/x/crypto v0.37.0 // indirect
5151
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
5252
golang.org/x/net v0.23.0 // indirect
53-
golang.org/x/sync v0.6.0 // indirect
54-
golang.org/x/sys v0.18.0 // indirect
55-
golang.org/x/text v0.14.0 // indirect
53+
golang.org/x/sync v0.13.0 // indirect
54+
golang.org/x/sys v0.32.0 // indirect
55+
golang.org/x/text v0.24.0 // indirect
5656
gopkg.in/ini.v1 v1.67.0 // indirect
5757
gopkg.in/yaml.v3 v3.0.1 // indirect
5858
)

go.sum

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI
3838
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
3939
github.com/jackc/pgproto3/v2 v2.3.3 h1:1HLSx5H+tXR9pW3in3zaztoEwQYRC9SQaYUHjTSUOag=
4040
github.com/jackc/pgproto3/v2 v2.3.3/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA=
41-
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
42-
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
43-
github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY=
44-
github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw=
45-
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
46-
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
41+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
42+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
43+
github.com/jackc/pgx/v5 v5.7.5 h1:JHGfMnQY+IEtGM63d+NGMjoRpysB2JBwDr5fsngwmJs=
44+
github.com/jackc/pgx/v5 v5.7.5/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
45+
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
46+
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
4747
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
4848
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
4949
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@@ -101,18 +101,18 @@ go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
101101
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
102102
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
103103
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
104-
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
105-
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
104+
golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE=
105+
golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc=
106106
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
107107
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
108108
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
109109
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
110-
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
111-
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
112-
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
113-
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
114-
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
115-
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
110+
golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610=
111+
golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
112+
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
113+
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
114+
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
115+
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
116116
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
117117
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
118118
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

internal/infra/uuid7/uuid7.go

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

11-
//nolint:gomnd
11+
//nolint:mnd
1212
func FromTime(timestamp time.Time) string {
1313
// Convert timestamp to Unix time in milliseconds
1414
unixMillis := timestamp.UnixNano() / int64(time.Millisecond)
@@ -17,8 +17,8 @@ func FromTime(timestamp time.Time) string {
1717
// Ensure the slice is initially 8 bytes to accommodate the full uint64,
1818
// but we'll only use the last 6 bytes for the timestamp
1919
timeBytes := make([]byte, 8)
20-
binary.BigEndian.PutUint64(timeBytes, uint64(unixMillis))
21-
timeBytes = timeBytes[2:] // Keep the last 6 bytes
20+
binary.BigEndian.PutUint64(timeBytes, uint64(unixMillis)) //nolint:gosec
21+
timeBytes = timeBytes[2:] // Keep the last 6 bytes
2222

2323
// Generate random bytes for the rest of the UUID (10 bytes to make it a total of 16)
2424
randomBytes := make([]byte, 10)

pkg/ppm/bounds.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ func parseBoundAsUUIDv7(partition postgresql.PartitionResult) (lowerBound, upper
114114
}
115115

116116
func convertToDateTimeWithoutTimezone(bound time.Time) time.Time {
117-
parsedTime, err := time.Parse("2006-01-02 15:04:05", bound.UTC().Format("2006-01-02 15:04:05"))
117+
/* Remove the time zone offset without rotating the timestamp to UTC */
118+
parsedTime, err := time.Parse("2006-01-02 15:04:05", bound.Format("2006-01-02 15:04:05"))
118119
if err != nil {
119120
return time.Time{}
120121
}

pkg/ppm/bounds_internal_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ func TestParseBounds(t *testing.T) {
4545
LowerBound: "2024-01-01 23:30:00-01",
4646
UpperBound: "2025-02-03 00:30:00+01",
4747
},
48-
"2024-01-02T00:30:00Z",
49-
"2025-02-02T23:30:00Z",
48+
"2024-01-01T23:30:00Z",
49+
"2025-02-03T00:30:00Z",
5050
},
5151
{
5252
"UUIDv7 bounds",

0 commit comments

Comments
 (0)