Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Postgres17 (+ misc linting changes) #187

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
pg_package: ["postgresql14", "postgresql15", "postgresql16"]
include:
- base_image: "golang:1.20.14-alpine3.19"
pg_package: "postgresql14"
- base_image: "golang:1.20.14-alpine3.19"
pg_package: "postgresql15"
- base_image: "golang:1.20.14-alpine3.19"
pg_package: "postgresql16"
- base_image: "golang:1.22.10-alpine3.21"
pg_package: "postgresql17"
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Build Docker image
run: docker build -t pg-schema-diff-test-runner -f ./build/Dockerfile.test --build-arg POSTGRES_PACKAGE=${{ matrix.pg_package }} .
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 }} .
- name: Run tests
run: docker run pg-schema-diff-test-runner
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
linters:
disable-all: true
enable:
- gofmt
- goimports
- ineffassign
- staticcheck
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ for _, stmt := range plan.Statements {
```

# Supported Postgres versions
Supported: 14, 15, 16
Supported: 14, 15, 16, 17
Unsupported: <= 13 are not supported. Use at your own risk.

# Unsupported migrations
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile.lint
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master
# Install sqlfluff
RUN pip install wheel # It complains if we attempt to install this in the same command as Cython
RUN pip install "Cython<3.0" pyyaml --no-build-isolation # Fix for https://github.com/yaml/pyyaml/issues/601
RUN pip install "sqlfluff==2.1.2"
RUN pip install "sqlfluff==3.3.0"

WORKDIR /pg-schema-diff
COPY . .
Expand Down
5 changes: 3 additions & 2 deletions build/Dockerfile.test
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM golang:1.20.14-alpine3.19
ARG BASE_IMAGE=golang:1.20.14-alpine3.19

ARG POSTGRES_PACKAGE=postgresql14
FROM $BASE_IMAGE

ARG POSTGRES_PACKAGE=postgresql14
RUN apk update && \
apk add --no-cache \
build-base \
Expand Down
2 changes: 1 addition & 1 deletion internal/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (g *Graph[V]) HasVertexWithId(id string) bool {
// Reverse reverses the edges of the map. The sources become the sinks and vice versa.
func (g *Graph[V]) Reverse() {
reversedEdges := make(AdjacencyMatrix)
for vertexId, _ := range g.verticesById {
for vertexId := range g.verticesById {
reversedEdges[vertexId] = make(map[string]bool)
}
for source, adjacentEdgesMap := range g.edges {
Expand Down
4 changes: 2 additions & 2 deletions internal/graph/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestCopy(t *testing.T) {
"shared_1", "shared_2", "shared_3", "g_1", "g_2", "g_3",
})

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

func getVertexIds(g *Graph[vertex]) []string {
var output []string
for id, _ := range g.verticesById {
for id := range g.verticesById {
output = append(output, id)
}
return output
Expand Down
2 changes: 1 addition & 1 deletion internal/migration_acceptance_tests/sequence_cases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ var sequenceAcceptanceTests = []acceptanceTestCase{
},
},
{
name: "And and Drop sequences (conflicing schemas)",
name: "And and Drop sequences (conflicting schemas)",
oldSchemaDDL: []string{
`
CREATE SCHEMA schema_1;
Expand Down
2 changes: 1 addition & 1 deletion internal/queries/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ WHERE
AND seq_ns.nspname !~ '^pg_temp'
-- Exclude sequences owned by identity columns.
-- These manifest as internal dependency on the column
AND (depend.deptype IS NULL OR depend.deptype != 'i')
AND (depend.deptype IS null OR depend.deptype != 'i')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new version of sqlfluff converts all caps NULL to null, which ensures consistency. Other occurences of null in this file are also lowercase.

-- Exclude sequences belonging to extensions
AND NOT EXISTS (
SELECT ext_depend.objid
Expand Down
2 changes: 1 addition & 1 deletion internal/queries/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/diff/sql_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var (
}
migrationHazardExtensionDroppedCannotTrackDependencies = MigrationHazard{
Type: MigrationHazardTypeHasUntrackableDependencies,
Message: "This extension may be in use by tables, indexes, functions, triggers, etc. Tihs statement will be ran last, so this may be OK.",
Message: "This extension may be in use by tables, indexes, functions, triggers, etc. This statement will be ran last, so this may be OK.",
}
migrationHazardExtensionAlteredVersionUpgraded = MigrationHazard{
Type: MigrationHazardTypeExtensionVersionUpgrade,
Expand Down
6 changes: 3 additions & 3 deletions pkg/diff/transform_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// original SchemaDiff struct
func dataPackNewTables(s schemaDiff) schemaDiff {
copiedNewTables := append([]schema.Table(nil), s.tableDiffs.adds...)
for i, _ := range copiedNewTables {
for i := range copiedNewTables {
copiedColumns := append([]schema.Column(nil), copiedNewTables[i].Columns...)
copiedNewTables[i].Columns = copiedColumns
sort.Slice(copiedColumns, func(i, j int) bool {
Expand All @@ -31,9 +31,9 @@ func dataPackNewTables(s schemaDiff) schemaDiff {
// generator to ignore changes to column ordering
func removeChangesToColumnOrdering(s schemaDiff) schemaDiff {
copiedTableDiffs := append([]tableDiff(nil), s.tableDiffs.alters...)
for i, _ := range copiedTableDiffs {
for i := range copiedTableDiffs {
copiedColDiffs := append([]columnDiff(nil), copiedTableDiffs[i].columnsDiff.alters...)
for i, _ := range copiedColDiffs {
for i := range copiedColDiffs {
copiedColDiffs[i].oldOrdering = copiedColDiffs[i].newOrdering
}
copiedTableDiffs[i].columnsDiff.alters = copiedColDiffs
Expand Down
Loading