Skip to content

Commit 4ed856e

Browse files
bplunkett-stripealeclarson
authored andcommitted
Add support for Postgres17 (+ misc linting changes) (stripe#187)
1 parent 85460c4 commit 4ed856e

File tree

13 files changed

+35
-22
lines changed

13 files changed

+35
-22
lines changed

.github/workflows/run-tests.yaml

+10-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
pg_package: ["postgresql14", "postgresql15", "postgresql16"]
13+
include:
14+
- base_image: "golang:1.20.14-alpine3.19"
15+
pg_package: "postgresql14"
16+
- base_image: "golang:1.20.14-alpine3.19"
17+
pg_package: "postgresql15"
18+
- base_image: "golang:1.20.14-alpine3.19"
19+
pg_package: "postgresql16"
20+
- base_image: "golang:1.22.10-alpine3.21"
21+
pg_package: "postgresql17"
1422
steps:
1523
- name: Checkout code
1624
uses: actions/checkout@v3
1725
- name: Build Docker image
18-
run: docker build -t pg-schema-diff-test-runner -f ./build/Dockerfile.test --build-arg POSTGRES_PACKAGE=${{ matrix.pg_package }} .
26+
run: docker build -t pg-schema-diff-test-runner -f ./build/Dockerfile.test --build-arg BASE_IMAGE=${{ matrix.base_image }} --build-arg POSTGRES_PACKAGE=${{ matrix.pg_package }} .
1927
- name: Run tests
2028
run: docker run pg-schema-diff-test-runner

.golangci.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
linters:
22
disable-all: true
33
enable:
4+
- gofmt
45
- goimports
56
- ineffassign
67
- staticcheck

build/Dockerfile.lint

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master
1111
# Install sqlfluff
1212
RUN pip install wheel # It complains if we attempt to install this in the same command as Cython
1313
RUN pip install "Cython<3.0" pyyaml --no-build-isolation # Fix for https://github.com/yaml/pyyaml/issues/601
14-
RUN pip install "sqlfluff==2.1.2"
14+
RUN pip install "sqlfluff==3.3.0"
1515

1616
WORKDIR /pg-schema-diff
1717
COPY . .

build/Dockerfile.test

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
FROM golang:1.20.14-alpine3.19
1+
ARG BASE_IMAGE=golang:1.20.14-alpine3.19
22

3-
ARG POSTGRES_PACKAGE=postgresql14
3+
FROM $BASE_IMAGE
44

5+
ARG POSTGRES_PACKAGE=postgresql14
56
RUN apk update && \
67
apk add --no-cache \
78
build-base \

internal/graph/graph.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (g *Graph[V]) HasVertexWithId(id string) bool {
8888
// Reverse reverses the edges of the map. The sources become the sinks and vice versa.
8989
func (g *Graph[V]) Reverse() {
9090
reversedEdges := make(AdjacencyMatrix)
91-
for vertexId, _ := range g.verticesById {
91+
for vertexId := range g.verticesById {
9292
reversedEdges[vertexId] = make(map[string]bool)
9393
}
9494
for source, adjacentEdgesMap := range g.edges {

internal/graph/graph_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func TestCopy(t *testing.T) {
136136
"shared_1", "shared_2", "shared_3", "g_1", "g_2", "g_3",
137137
})
138138

139-
// validate overrides weren't copied over and non-overriden shared nodes are the same
139+
// validate overrides weren't copied over and non-overridden shared nodes are the same
140140
assert.NotEqual(t, g.GetVertex("shared_1"), gC.GetVertex("shared_1"))
141141
assert.Equal(t, gC.GetVertex("shared_1"), copyOverrideShared1)
142142
assert.NotEqual(t, g.GetVertex("shared_2"), gC.GetVertex("shared_2"))
@@ -425,7 +425,7 @@ func (v vertex) GetId() string {
425425

426426
func getVertexIds(g *Graph[vertex]) []string {
427427
var output []string
428-
for id, _ := range g.verticesById {
428+
for id := range g.verticesById {
429429
output = append(output, id)
430430
}
431431
return output

internal/migration_acceptance_tests/sequence_cases_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ var sequenceAcceptanceTests = []acceptanceTestCase{
200200
},
201201
},
202202
{
203-
name: "And and Drop sequences (conflicing schemas)",
203+
name: "And and Drop sequences (conflicting schemas)",
204204
oldSchemaDDL: []string{
205205
`
206206
CREATE SCHEMA schema_1;

internal/queries/queries.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ WHERE
342342
AND seq_ns.nspname !~ '^pg_temp'
343343
-- Exclude sequences owned by identity columns.
344344
-- These manifest as internal dependency on the column
345-
AND (depend.deptype IS NULL OR depend.deptype != 'i')
345+
AND (depend.deptype IS null OR depend.deptype != 'i')
346346
-- Exclude sequences belonging to extensions
347347
AND NOT EXISTS (
348348
SELECT ext_depend.objid

internal/queries/queries.sql.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/schema/schema.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,8 @@ func (s *schemaFetcher) buildTable(
865865
}
866866

867867
var identity *ColumnIdentity
868-
if len(column.IdentityType) > 0 {
868+
if len(column.IdentityType) > 0 && table.ParentTableName == "" {
869+
// Exclude identity columns from table partitions because they are owned by the parent.
869870
identity = &ColumnIdentity{
870871
Type: ColumnIdentityType(column.IdentityType),
871872
StartValue: column.StartValue.Int64,

internal/schema/schema_test.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ var (
469469
content TEXT DEFAULT '',
470470
genre VARCHAR(256) NOT NULL,
471471
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP CHECK (created_at > CURRENT_TIMESTAMP - interval '1 month'),
472-
version INT NOT NULL DEFAULT 0,
472+
version INT GENERATED ALWAYS AS IDENTITY,
473473
PRIMARY KEY (author, id)
474474
) PARTITION BY LIST (author);
475475
ALTER TABLE foo ADD CONSTRAINT author_check CHECK (author IS NOT NULL AND LENGTH(author) > 0) NOT VALID;
@@ -524,7 +524,7 @@ var (
524524
ALTER TABLE foo_fk_1 ADD CONSTRAINT foo_fk_1_fk FOREIGN KEY (author, content) REFERENCES foo_1 (author, content)
525525
NOT VALID;
526526
`},
527-
expectedHash: "cf473d75363e9f77",
527+
expectedHash: "38588fed86b25fd",
528528
expectedSchema: Schema{
529529
NamedSchemas: []NamedSchema{
530530
{Name: "public"},
@@ -538,7 +538,9 @@ var (
538538
{Name: "content", Type: "text", Default: "''::text", IsNullable: true, Size: -1, Collation: defaultCollation},
539539
{Name: "genre", Type: "character varying(256)", Size: -1, Collation: defaultCollation},
540540
{Name: "created_at", Type: "timestamp without time zone", Default: "CURRENT_TIMESTAMP", Size: 8},
541-
{Name: "version", Type: "integer", Default: "0", Size: 4},
541+
{Name: "version", Type: "integer", Size: 4,
542+
Identity: &ColumnIdentity{Type: "a", MinValue: 1, MaxValue: 2147483647, StartValue: 1, Increment: 1, CacheSize: 1, Cycle: false},
543+
},
542544
},
543545
CheckConstraints: []CheckConstraint{
544546
{Name: "author_check", Expression: "((author IS NOT NULL) AND (length(author) > 0))", IsInheritable: true, KeyColumns: []string{"author"}},
@@ -557,7 +559,7 @@ var (
557559
{Name: "content", Type: "text", Default: "''::text", Size: -1, Collation: defaultCollation},
558560
{Name: "genre", Type: "character varying(256)", Size: -1, Collation: defaultCollation},
559561
{Name: "created_at", Type: "timestamp without time zone", Default: "CURRENT_TIMESTAMP", Size: 8},
560-
{Name: "version", Type: "integer", Default: "0", Size: 4},
562+
{Name: "version", Type: "integer", IsNullable: false, Size: 4},
561563
},
562564
CheckConstraints: nil,
563565
ReplicaIdentity: ReplicaIdentityNothing,
@@ -572,7 +574,7 @@ var (
572574
{Name: "content", Type: "text", Default: "''::text", IsNullable: true, Size: -1, Collation: defaultCollation},
573575
{Name: "genre", Type: "character varying(256)", Size: -1, Collation: defaultCollation},
574576
{Name: "created_at", Type: "timestamp without time zone", Default: "CURRENT_TIMESTAMP", Size: 8},
575-
{Name: "version", Type: "integer", Default: "0", Size: 4},
577+
{Name: "version", Type: "integer", IsNullable: false, Size: 4},
576578
},
577579
CheckConstraints: nil,
578580
ReplicaIdentity: ReplicaIdentityDefault,
@@ -587,7 +589,7 @@ var (
587589
{Name: "content", Type: "text", Default: "''::text", IsNullable: true, Size: -1, Collation: defaultCollation},
588590
{Name: "genre", Type: "character varying(256)", Size: -1, Collation: defaultCollation},
589591
{Name: "created_at", Type: "timestamp without time zone", Default: "CURRENT_TIMESTAMP", Size: 8},
590-
{Name: "version", Type: "integer", Default: "0", Size: 4},
592+
{Name: "version", Type: "integer", IsNullable: false, Size: 4},
591593
},
592594
CheckConstraints: nil,
593595
ReplicaIdentity: ReplicaIdentityDefault,

pkg/diff/sql_generator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var (
5555
}
5656
migrationHazardExtensionDroppedCannotTrackDependencies = MigrationHazard{
5757
Type: MigrationHazardTypeHasUntrackableDependencies,
58-
Message: "This extension may be in use by tables, indexes, functions, triggers, etc. Tihs statement will be ran last, so this may be OK.",
58+
Message: "This extension may be in use by tables, indexes, functions, triggers, etc. This statement will be ran last, so this may be OK.",
5959
}
6060
migrationHazardExtensionAlteredVersionUpgraded = MigrationHazard{
6161
Type: MigrationHazardTypeExtensionVersionUpgrade,

pkg/diff/transform_diff.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
// original SchemaDiff struct
1515
func dataPackNewTables(s schemaDiff) schemaDiff {
1616
copiedNewTables := append([]schema.Table(nil), s.tableDiffs.adds...)
17-
for i, _ := range copiedNewTables {
17+
for i := range copiedNewTables {
1818
copiedColumns := append([]schema.Column(nil), copiedNewTables[i].Columns...)
1919
copiedNewTables[i].Columns = copiedColumns
2020
sort.Slice(copiedColumns, func(i, j int) bool {
@@ -31,9 +31,9 @@ func dataPackNewTables(s schemaDiff) schemaDiff {
3131
// generator to ignore changes to column ordering
3232
func removeChangesToColumnOrdering(s schemaDiff) schemaDiff {
3333
copiedTableDiffs := append([]tableDiff(nil), s.tableDiffs.alters...)
34-
for i, _ := range copiedTableDiffs {
34+
for i := range copiedTableDiffs {
3535
copiedColDiffs := append([]columnDiff(nil), copiedTableDiffs[i].columnsDiff.alters...)
36-
for i, _ := range copiedColDiffs {
36+
for i := range copiedColDiffs {
3737
copiedColDiffs[i].oldOrdering = copiedColDiffs[i].newOrdering
3838
}
3939
copiedTableDiffs[i].columnsDiff.alters = copiedColDiffs

0 commit comments

Comments
 (0)