Skip to content

Commit 9b2dc5c

Browse files
committed
fix: handle pg 18 not_null suffix indexes
1 parent 47d86f6 commit 9b2dc5c

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

.github/workflows/test.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
services:
1212
postgres:
13-
image: docker.io/library/postgres:16.4
13+
image: docker.io/library/postgres:18
1414
env:
1515
POSTGRES_PASSWORD: ""
1616
POSTGRES_HOST_AUTH_METHOD: trust
@@ -23,10 +23,10 @@ jobs:
2323
--health-retries 5
2424
2525
steps:
26-
- uses: actions/checkout@v3
27-
- uses: extractions/setup-just@v2
28-
- uses: actions/setup-go@v5
26+
- uses: actions/checkout@v5
27+
- uses: extractions/setup-just@v4
28+
- uses: actions/setup-go@v6
2929
with:
30-
go-version: '^1.24'
30+
go-version: '^1.25'
3131

3232
- run: just test-race

hack/compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
postgres:
3-
image: docker.io/library/postgres:16
3+
image: docker.io/library/postgres:18
44
environment:
55
POSTGRES_PASSWORD: ""
66
POSTGRES_HOST_AUTH_METHOD: trust

internal/sql/adapter/postgres/catalog.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ ORDER BY conrelid::regclass::text, contype DESC;
106106
for _, idxSchema := range indexList {
107107
t := cat.Table(idxSchema.TABLE_NAME)
108108

109-
t.(sqlbuilder.KeyCollectionManager).AddKey(idxSchema.ToKey(t))
109+
key := idxSchema.ToKey(t)
110+
if key == nil {
111+
continue
112+
}
113+
114+
t.(sqlbuilder.KeyCollectionManager).AddKey(key)
110115
}
111116
}
112117

@@ -185,6 +190,13 @@ func (indexSchema) TableName() string {
185190
}
186191

187192
func (idxSchema *indexSchema) ToKey(table sqlbuilder.Table) sqlbuilder.Key {
193+
// ignore pg 18 not_null indexes
194+
// https://www.enterprisedb.com/blog/changes-not-null-postgres-18?utm_source=chatgpt.com
195+
// https://www.postgresql.org/docs/current/ddl-constraints.html#DDL-CONSTRAINTS-NOT-NULL
196+
if strings.HasPrefix(idxSchema.INDEX_DEF, "NOT NULL ") {
197+
return nil
198+
}
199+
188200
isUnique := strings.Contains(idxSchema.INDEX_DEF, "UNIQUE")
189201
method := ""
190202
name := ""
@@ -197,9 +209,9 @@ func (idxSchema *indexSchema) ToKey(table sqlbuilder.Table) sqlbuilder.Key {
197209
name = "PRIMARY"
198210
colParts = idxSchema.INDEX_DEF[len("PRIMARY KEY"):]
199211
} else {
212+
// USING <method> (f_col_1,f_col_2)
200213
name = strings.ToLower(idxSchema.INDEX_NAME[len(table.TableName())+1:])
201214
method = strings.ToUpper(reUsing.FindString(idxSchema.INDEX_DEF)[6:])
202-
// USING
203215
colParts = strings.TrimSpace(reUsing.Split(idxSchema.INDEX_DEF, 2)[1])
204216
}
205217

0 commit comments

Comments
 (0)