diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index e041eca..8579dd7 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -23,10 +23,10 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-go@v5 with: - go-version: '1.20' + go-version: '1.25.0' cache: false - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v9 with: - version: v1.56.2 + version: v2.7.0 diff --git a/.golangci.yaml b/.golangci.yaml index 468fd55..ede003b 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,10 +1,11 @@ +version: "2" linters: - disable-all: true + default: none enable: - - gofmt - - goimports - - ineffassign - - staticcheck - - typecheck - - unused - + - ineffassign + - staticcheck + - unused +formatters: + enable: + - gofmt + - goimports \ No newline at end of file diff --git a/build/Dockerfile.codegen b/build/Dockerfile.codegen index a19431a..cf01907 100644 --- a/build/Dockerfile.codegen +++ b/build/Dockerfile.codegen @@ -1,4 +1,4 @@ -FROM golang:1.20-bookworm +FROM golang:1.25-bookworm RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ diff --git a/build/Dockerfile.lint b/build/Dockerfile.lint index 2d90804..10e456f 100644 --- a/build/Dockerfile.lint +++ b/build/Dockerfile.lint @@ -1,4 +1,4 @@ -FROM golang:1.20-bookworm +FROM golang:1.25-bookworm RUN apt-get update && apt-get install -y --no-install-recommends \ make \ @@ -8,7 +8,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ && rm -rf /var/lib/apt/lists/* # Install golang-ci-lint -RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.56.2 +RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v2.7.0 # Install sqlfluff (use --break-system-packages for Debian 12+) RUN pip install --break-system-packages wheel diff --git a/build/Dockerfile.test b/build/Dockerfile.test index e9c5a6a..38361fe 100644 --- a/build/Dockerfile.test +++ b/build/Dockerfile.test @@ -1,4 +1,4 @@ -FROM golang:1.22-bookworm +FROM golang:1.25-bookworm ARG PG_VERSION=14 diff --git a/cmd/pg-schema-diff/apply_cmd.go b/cmd/pg-schema-diff/apply_cmd.go index f9a2d77..4d8876b 100644 --- a/cmd/pg-schema-diff/apply_cmd.go +++ b/cmd/pg-schema-diff/apply_cmd.go @@ -2,7 +2,6 @@ package main import ( "context" - "errors" "fmt" "sort" "strings" @@ -112,13 +111,11 @@ func failIfHazardsNotAllowed(plan diff.Plan, allowedHazardsTypesStrs []string) e } if len(disallowedHazardMsgs) > 0 { - return errors.New(fmt.Sprintf( - "Prohited hazards found\n"+ - "These hazards must be allowed via the allow-hazards flag, e.g., --allow-hazards %s\n"+ - "Prohibited hazards in the following statements:\n%s", + return fmt.Errorf("prohited hazards found\n"+ + "These hazards must be allowed via the allow-hazards flag, e.g., --allow-hazards %s\n"+ + "Prohibited hazards in the following statements:\n%s", strings.Join(getHazardTypes(plan), ","), - strings.Join(disallowedHazardMsgs, "\n"), - )) + strings.Join(disallowedHazardMsgs, "\n")) } return nil } diff --git a/go.mod b/go.mod index 202a16b..9e29312 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/stripe/pg-schema-diff -go 1.20 +go 1.25.5 require ( github.com/go-logfmt/logfmt v0.6.0 @@ -14,7 +14,7 @@ require ( github.com/mitchellh/hashstructure/v2 v2.0.2 github.com/spf13/cobra v1.7.0 github.com/stretchr/testify v1.8.2 - golang.org/x/sync v0.10.0 + golang.org/x/sync v0.18.0 ) require ( @@ -32,8 +32,8 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.9.0 // indirect github.com/spf13/pflag v1.0.5 // indirect - golang.org/x/crypto v0.31.0 // indirect - golang.org/x/sys v0.28.0 // indirect - golang.org/x/text v0.21.0 // indirect + golang.org/x/crypto v0.45.0 // indirect + golang.org/x/sys v0.38.0 // indirect + golang.org/x/text v0.31.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index ec56ac1..656391e 100644 --- a/go.sum +++ b/go.sum @@ -162,8 +162,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= -golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= +golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q= +golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= @@ -173,8 +173,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= -golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I= +golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -188,8 +188,8 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= -golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc= +golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -197,8 +197,8 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= -golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM= +golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= diff --git a/internal/schema/schema.go b/internal/schema/schema.go index a1599a0..1a6a948 100644 --- a/internal/schema/schema.go +++ b/internal/schema/schema.go @@ -524,9 +524,7 @@ type ( // via WithIncludeSchemas. If empty, then all schemas are included. func WithIncludeSchemas(schemas ...string) GetSchemaOpt { return func(o *getSchemaOptions) { - for _, schema := range schemas { - o.includeSchemas = append(o.includeSchemas, schema) - } + o.includeSchemas = append(o.includeSchemas, schemas...) } } diff --git a/internal/util/closer_test.go b/internal/util/closer_test.go index 1c64ea7..6f6cd8c 100644 --- a/internal/util/closer_test.go +++ b/internal/util/closer_test.go @@ -23,7 +23,6 @@ func TestDoOnErrOrPanicIsCalledOnError(t *testing.T) { }) err = fmt.Errorf("some error") - return } func TestDoOnErrOrPanicIsNotCalledOnNoError(t *testing.T) { @@ -35,8 +34,6 @@ func TestDoOnErrOrPanicIsNotCalledOnNoError(t *testing.T) { defer util.DoOnErrOrPanic(&err, func() { wasCalled = true }) - - return } func TestDoOnErrOrPanicIsCalledOnPanic(t *testing.T) { diff --git a/pkg/diff/policy_sql_generator.go b/pkg/diff/policy_sql_generator.go index 79ecd4b..370df96 100644 --- a/pkg/diff/policy_sql_generator.go +++ b/pkg/diff/policy_sql_generator.go @@ -135,7 +135,7 @@ func newPolicySQLVertexGenerator(oldTable *schema.Table, table schema.Table) (sq var oldSchemaColumnsByName map[string]schema.Column if oldTable != nil { if oldTable.SchemaQualifiedName != table.SchemaQualifiedName { - return nil, fmt.Errorf("old and new tables must have the same schema-qualified name. new=%s, old=%s", table.SchemaQualifiedName.GetFQEscapedName(), oldTable.SchemaQualifiedName.GetFQEscapedName()) + return nil, fmt.Errorf("old and new tables must have the same schema-qualified name. new=%s, old=%s", table.GetFQEscapedName(), oldTable.GetFQEscapedName()) } oldSchemaColumnsByName = buildSchemaObjByNameMap(oldTable.Columns) } diff --git a/pkg/diff/sql_generator.go b/pkg/diff/sql_generator.go index 064a809..bb38a38 100644 --- a/pkg/diff/sql_generator.go +++ b/pkg/diff/sql_generator.go @@ -726,9 +726,7 @@ func buildChildrenByPartitionedIndexNameMap(indexes []schema.Index) map[string][ rootsByChildIdxName[idx.GetName()] = rootIdx // We can now calculate the next level of children for this node - for _, child := range childrenByDirectParentIdxName[idx.GetName()] { - currentNodes = append(currentNodes, child) - } + currentNodes = append(currentNodes, childrenByDirectParentIdxName[idx.GetName()]...) } // Build a map of all children by the root index name using the result of the previous step @@ -2150,7 +2148,7 @@ func (*attachPartitionSQLVertexGenerator) Add(table schema.Table) ([]Statement, } return []Statement{{ - DDL: fmt.Sprintf("%s ATTACH PARTITION %s %s", alterTablePrefix(*table.ParentTable), table.SchemaQualifiedName.GetFQEscapedName(), table.ForValues), + DDL: fmt.Sprintf("%s ATTACH PARTITION %s %s", alterTablePrefix(*table.ParentTable), table.GetFQEscapedName(), table.ForValues), Timeout: statementTimeoutDefault, LockTimeout: lockTimeoutDefault, }}, nil @@ -2557,7 +2555,7 @@ func (s sequenceOwnershipSQLVertexGenerator) buildAlterOwnershipStmt(new schema. } func (s sequenceOwnershipSQLVertexGenerator) GetSQLVertexId(seq schema.Sequence, diffType diffType) sqlVertexId { - return buildSchemaObjVertexId("sequence_ownership", seq.SchemaQualifiedName.GetFQEscapedName(), diffType) + return buildSchemaObjVertexId("sequence_ownership", seq.GetFQEscapedName(), diffType) } func (s sequenceOwnershipSQLVertexGenerator) GetAddAlterDependencies(new schema.Sequence, old schema.Sequence) ([]dependency, error) {