diff --git a/.gitignore b/.gitignore index 079249e..32bdcff 100644 --- a/.gitignore +++ b/.gitignore @@ -70,3 +70,4 @@ tags # End of https://www.gitignore.io/api/go,vim,macos bin +.idea diff --git a/.go-version b/.go-version index 01b7568..14bee92 100644 --- a/.go-version +++ b/.go-version @@ -1 +1 @@ -1.13.3 +1.23.2 diff --git a/.golangci.yml b/.golangci.yml index 0ebe33e..926a3c9 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,25 +1,44 @@ -output: - format: tab linters: disable-all: true enable: - - deadcode - - depguard - - dupl - - goconst + - asciicheck + - bodyclose + - copyloopvar + - decorder + - dogsled + - dupword + - err113 + - errcheck + - exhaustive + - gocheckcompilerdirectives - gocritic - - gocyclo - - gofmt + - godot + - goheader - goimports - - golint - gosec + - gosimple - govet + - grouper + - importas + - inamedparam - ineffassign + - interfacebloat - misspell - - prealloc + - nosprintfhostport + - perfsprint + - predeclared + - revive + - staticcheck + - stylecheck - typecheck - unconvert - - varcheck + - unparam + - unused + - whitespace +linters-settings: + gosec: + excludes: + - G306 # Expect WriteFile permissions to be 0600 or less issues: exclude-use-default: false max-per-linter: 0 @@ -28,3 +47,22 @@ issues: - path: _test\.go linters: - dupl + - path: create_test.go + text: G404 # Use of weak random number generator + # The tableName struct field is used by go-pg, even if we don't use it + # directly. + - linters: + - unused + text: tableName + # We don't care about any errors from the releaseLock function. + - linters: + - errcheck + source: releaseLock + # We don't care about package comments. + - linters: + - revive + text: package-comments + # We return dynamic errors. + - linters: + - err113 + text: do not define dynamic errors diff --git a/.travis.yml b/.travis.yml index 6ccff69..d8ea5ce 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,11 +4,9 @@ language: go services: - postgresql go: - - 1.13.x - - 1.14.x - - 1.15.x -env: - - GO111MODULE=on + - 1.21.x + - 1.22.x + - 1.23.x install: - make setup - make install diff --git a/Makefile b/Makefile index 8f23613..ffe4fd3 100644 --- a/Makefile +++ b/Makefile @@ -84,9 +84,9 @@ endif $(BIN_DIR)/golangci-lint: @echo "---> Installing linter" - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(BIN_DIR) v1.21.0 + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(BIN_DIR) v1.61.0 .PHONY: test test: @echo "---> Testing" - TEST_DATABASE_USER=$(TEST_DATABASE_USER) TEST_DATABASE_NAME=$(TEST_DATABASE_NAME) go test -v . -coverprofile $(COVERAGE_PROFILE) + TEST_DATABASE_USER=$(TEST_DATABASE_USER) TEST_DATABASE_NAME=$(TEST_DATABASE_NAME) go test . -coverprofile $(COVERAGE_PROFILE) diff --git a/create.go b/create.go index 1aa0dd4..05d8ed6 100644 --- a/create.go +++ b/create.go @@ -2,7 +2,7 @@ package migrations import ( "fmt" - "io/ioutil" + "os" "path" "time" ) @@ -36,9 +36,9 @@ func init() { func create(directory, name string) error { version := time.Now().UTC().Format(timeFormat) fullname := fmt.Sprintf("%s_%s", version, name) - filename := path.Join(directory, fmt.Sprintf("%s.go", fullname)) + filename := path.Join(directory, fullname+".go") fmt.Printf("Creating %s...\n", filename) - return ioutil.WriteFile(filename, []byte(fmt.Sprintf(template, fullname)), 0644) + return os.WriteFile(filename, []byte(fmt.Sprintf(template, fullname)), 0644) } diff --git a/create_test.go b/create_test.go index 59f9a1e..252bf0b 100644 --- a/create_test.go +++ b/create_test.go @@ -2,7 +2,6 @@ package migrations import ( "fmt" - "io/ioutil" "math/rand" "os" "strings" @@ -20,7 +19,7 @@ func TestCreate(t *testing.T) { err := create(tmp, name) assert.Nil(t, err) - files, err := ioutil.ReadDir(tmp) + files, err := os.ReadDir(tmp) assert.Nil(t, err) found := false diff --git a/go.mod b/go.mod index 6d0d143..41b6ab7 100644 --- a/go.mod +++ b/go.mod @@ -1,21 +1,42 @@ module github.com/robinjoseph08/go-pg-migrations/v3 -go 1.13 +go 1.23 require ( - github.com/fatih/color v1.7.0 // indirect github.com/git-chglog/git-chglog v0.0.0-20200414013904-db796966b373 github.com/go-pg/pg/v10 v10.5.0 - github.com/imdario/mergo v0.3.8 // indirect - github.com/mattn/go-colorable v0.1.4 // indirect github.com/mattn/goveralls v0.0.6 github.com/stretchr/testify v1.6.1 +) + +require ( + github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/fatih/color v1.7.0 // indirect + github.com/go-pg/zerochecker v0.2.0 // indirect + github.com/imdario/mergo v0.3.8 // indirect + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect + github.com/mattn/go-colorable v0.1.4 // indirect + github.com/mattn/go-isatty v0.0.8 // indirect + github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/russross/blackfriday/v2 v2.0.1 // indirect + github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect + github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect github.com/tsuyoshiwada/go-gitcmd v0.0.0-20180205145712-5f1f5f9475df // indirect github.com/urfave/cli v1.22.1 // indirect + github.com/vmihailenco/bufpool v0.1.11 // indirect github.com/vmihailenco/msgpack/v5 v5.0.0-beta.8 // indirect + github.com/vmihailenco/tagparser v0.1.2 // indirect + go.opentelemetry.io/otel v0.13.0 // indirect golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 // indirect golang.org/x/net v0.0.0-20201026091529-146b70c837a4 // indirect golang.org/x/sys v0.0.0-20201026173827-119d4633e4d1 // indirect + golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375 // indirect gopkg.in/AlecAivazis/survey.v1 v1.8.7 // indirect gopkg.in/kyokomi/emoji.v1 v1.5.1 // indirect + gopkg.in/yaml.v2 v2.3.0 // indirect + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect + mellium.im/sasl v0.2.1 // indirect ) diff --git a/go.sum b/go.sum index b4af4ef..6784236 100644 --- a/go.sum +++ b/go.sum @@ -6,7 +6,6 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -14,7 +13,6 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= @@ -26,7 +24,6 @@ github.com/go-pg/zerochecker v0.2.0 h1:pp7f72c3DobMWOb2ErtZsnrPaSvHd2W4o9//8HtF4 github.com/go-pg/zerochecker v0.2.0/go.mod h1:NJZ4wKL0NmTtz0GKCoJ8kym6Xn/EQzXRl2OnAe7MmDo= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -35,23 +32,19 @@ github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0 h1:oOuy+ugB+P/kBdUnG5QaMXSIyJ1q38wWSojYCb3z5VQ= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174 h1:WlZsjVhE8Af9IcZDGgJGQpNflI3+MJSBhsgT5PCtzBQ= github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A= -github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= @@ -59,7 +52,6 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -96,7 +88,6 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5I github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -108,13 +99,10 @@ github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/vmihailenco/bufpool v0.1.11 h1:gOq2WmBrq0i2yW5QJ16ykccQ4wH9UyEsgLm6czKAd94= github.com/vmihailenco/bufpool v0.1.11/go.mod h1:AFf/MOy3l2CFTKbxwt0mp2MwnqjNEs5H/UxrkA5jxTQ= -github.com/vmihailenco/msgpack/v4 v4.3.11 h1:Q47CePddpNGNhk4GCnAx9DDtASi2rasatE0cd26cZoE= github.com/vmihailenco/msgpack/v4 v4.3.11/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= -github.com/vmihailenco/msgpack/v5 v5.0.0-beta.1 h1:d71/KA0LhvkrJ/Ok+Wx9qK7bU8meKA1Hk0jpVI5kJjk= github.com/vmihailenco/msgpack/v5 v5.0.0-beta.1/go.mod h1:xlngVLeyQ/Qi05oQxhQ+oTuqa03RjMwMfk/7/TCs+QI= github.com/vmihailenco/msgpack/v5 v5.0.0-beta.8 h1:R2L6zPq1pWFumpeIxAJoeiov5GxyEZUq9NyS8eus/6s= github.com/vmihailenco/msgpack/v5 v5.0.0-beta.8/go.mod h1:HVxBVPUK/+fZMonk4bi1islLa8V3cfnBug0+4dykPzo= -github.com/vmihailenco/tagparser v0.1.1 h1:quXMXlA39OCbd2wAdTsGDlK9RkOk6Wuw+x37wVyIuWY= github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= github.com/vmihailenco/tagparser v0.1.2 h1:gnjoVuB/kljJ5wICEEOpx98oXMWPLj22G67Vbd1qPqc= github.com/vmihailenco/tagparser v0.1.2/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= @@ -124,10 +112,8 @@ go.opentelemetry.io/otel v0.13.0/go.mod h1:dlSNewoRYikTkotEnxdmuBHgzT+k/idJSfDv/ golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee h1:4yd7jl+vXjalO5ztz6Vc1VADv+S/80LGJmyl1ROJ2AI= golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E= golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -144,24 +130,18 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201010224723-4f7140c49acb h1:mUVeFHoDKis5nxCAzoAi7E8Ghb86EXh/RK6wtvJIqRY= golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201026091529-146b70c837a4 h1:awiuzyrRjJDb+OXi9ceHO3SDxVoN3JER57mhtqkdQBs= golang.org/x/net v0.0.0-20201026091529-146b70c837a4/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180606202747-9527bec2660b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -175,13 +155,10 @@ golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 h1:9UQO31fZ+0aKQOFldThf7BKPMJTiBfWycGh/u3UoO88= golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201026173827-119d4633e4d1 h1:/DtoiOYKoQCcIFXQjz07RnWNPRCbqmSXSpgEzhC9ZHM= golang.org/x/sys v0.0.0-20201026173827-119d4633e4d1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -200,7 +177,6 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= @@ -212,27 +188,22 @@ google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLY google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0 h1:qdOKuR/EIArgaWNjetjgTzgVTAZ+S/WXVrq9HW9zimw= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= gopkg.in/AlecAivazis/survey.v1 v1.8.7 h1:oBJqtgsyBLg9K5FK9twNUbcPnbCPoh+R9a+7nag3qJM= gopkg.in/AlecAivazis/survey.v1 v1.8.7/go.mod h1:iBNOmqKz/NUbZx3bA+4hAGLRC7fSK7tgtVDT4tB22XA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/kyokomi/emoji.v1 v1.5.1 h1:beetH5mWDMzFznJ+Qzd5KVHp79YKhVUMcdO8LpRLeGw= gopkg.in/kyokomi/emoji.v1 v1.5.1/go.mod h1:N9AZ6hi1jHOPn34PsbpufQZUcKftSD7WgS2pgpmH4Lg= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= diff --git a/migrate.go b/migrate.go index 4e71719..514f09a 100644 --- a/migrate.go +++ b/migrate.go @@ -9,12 +9,12 @@ import ( "github.com/go-pg/pg/v10/orm" ) -var migrations []migration +var migrations []*migration // Register accepts a name, up, down, and options and adds the migration to the // global migrations slice. func Register(name string, up, down func(orm.DB) error, opts MigrationOptions) { - migrations = append(migrations, migration{ + migrations = append(migrations, &migration{ Name: name, Up: up, Down: down, @@ -81,7 +81,7 @@ func migrate(db *pg.DB) (err error) { } m.CompletedAt = time.Now() - _, err = db.Model(&m).Insert() + _, err = db.Model(m).Insert() if err != nil { return fmt.Errorf("%s: %s", m.Name, err) } @@ -91,8 +91,8 @@ func migrate(db *pg.DB) (err error) { return nil } -func getCompletedMigrations(db orm.DB) ([]migration, error) { - var completed []migration +func getCompletedMigrations(db orm.DB) ([]*migration, error) { + var completed []*migration err := db. Model(&completed). @@ -105,14 +105,14 @@ func getCompletedMigrations(db orm.DB) ([]migration, error) { return completed, nil } -func filterMigrations(all, subset []migration, wantCompleted bool) []migration { +func filterMigrations(all, subset []*migration, wantCompleted bool) []*migration { subsetMap := map[string]bool{} for _, c := range subset { subsetMap[c.Name] = true } - var d []migration + var d []*migration for _, a := range all { if subsetMap[a.Name] == wantCompleted { diff --git a/migrate_test.go b/migrate_test.go index 083879a..0dc1c11 100644 --- a/migrate_test.go +++ b/migrate_test.go @@ -60,7 +60,7 @@ func TestMigrate(t *testing.T) { t.Run("sorts migrations", func(tt *testing.T) { clearMigrations(tt, db) resetMigrations(tt) - migrations = []migration{ + migrations = []*migration{ {Name: "456", Up: noopMigration, Down: noopMigration}, {Name: "123", Up: noopMigration, Down: noopMigration}, } @@ -75,18 +75,18 @@ func TestMigrate(t *testing.T) { t.Run("only runs uncompleted migrations", func(tt *testing.T) { clearMigrations(tt, db) resetMigrations(tt) - migrations = []migration{ + migrations = []*migration{ {Name: "123", Up: noopMigration, Down: noopMigration, Batch: 1, CompletedAt: time.Now()}, {Name: "456", Up: noopMigration, Down: noopMigration}, } - _, err := db.Model(&migrations[0]).Insert() + _, err := db.Model(migrations[0]).Insert() assert.Nil(tt, err) err = migrate(db) assert.Nil(tt, err) - var m []migration + var m []*migration err = db.Model(&m).Order("name").Select() assert.Nil(tt, err) require.Len(tt, m, 2) @@ -97,7 +97,7 @@ func TestMigrate(t *testing.T) { t.Run("exits early if there aren't any migrations to run", func(tt *testing.T) { clearMigrations(tt, db) resetMigrations(tt) - migrations = []migration{ + migrations = []*migration{ {Name: "123", Up: noopMigration, Down: noopMigration, Batch: 1, CompletedAt: time.Now()}, {Name: "456", Up: noopMigration, Down: noopMigration, Batch: 1, CompletedAt: time.Now()}, } @@ -116,7 +116,7 @@ func TestMigrate(t *testing.T) { t.Run("returns an error if the migration lock is already held", func(tt *testing.T) { clearMigrations(tt, db) resetMigrations(tt) - migrations = []migration{ + migrations = []*migration{ {Name: "123", Up: noopMigration, Down: noopMigration}, {Name: "456", Up: noopMigration, Down: noopMigration}, } @@ -132,13 +132,13 @@ func TestMigrate(t *testing.T) { t.Run("increments batch number for each run and associates all migrations with it", func(tt *testing.T) { clearMigrations(tt, db) resetMigrations(tt) - migrations = []migration{ + migrations = []*migration{ {Name: "123", Up: noopMigration, Down: noopMigration, Batch: 5, CompletedAt: time.Now()}, {Name: "456", Up: noopMigration, Down: noopMigration}, {Name: "789", Up: noopMigration, Down: noopMigration}, } - _, err := db.Model(&migrations[0]).Insert() + _, err := db.Model(migrations[0]).Insert() assert.Nil(tt, err) err = migrate(db) @@ -156,7 +156,7 @@ func TestMigrate(t *testing.T) { t.Run(`runs "up" within a transaction if specified`, func(tt *testing.T) { clearMigrations(tt, db) resetMigrations(tt) - migrations = []migration{ + migrations = []*migration{ {Name: "123", Up: erringMigration, Down: noopMigration, DisableTransaction: false}, } @@ -169,7 +169,7 @@ func TestMigrate(t *testing.T) { t.Run(`doesn't run "up" within a transaction if specified`, func(tt *testing.T) { clearMigrations(tt, db) resetMigrations(tt) - migrations = []migration{ + migrations = []*migration{ {Name: "123", Up: erringMigration, Down: noopMigration, DisableTransaction: true}, } @@ -182,11 +182,11 @@ func TestMigrate(t *testing.T) { type logQueryHook struct{} -func (logQueryHook) BeforeQuery(ctx context.Context, event *pg.QueryEvent) (context.Context, error) { +func (logQueryHook) BeforeQuery(ctx context.Context, _ *pg.QueryEvent) (context.Context, error) { return ctx, nil } -func (qh logQueryHook) AfterQuery(ctx context.Context, event *pg.QueryEvent) error { +func (qh logQueryHook) AfterQuery(_ context.Context, event *pg.QueryEvent) error { query, err := event.FormattedQuery() if err != nil { return err @@ -199,7 +199,7 @@ func (qh logQueryHook) AfterQuery(ctx context.Context, event *pg.QueryEvent) err func resetMigrations(t *testing.T) { t.Helper() - migrations = []migration{} + migrations = []*migration{} } func clearMigrations(t *testing.T, db *pg.DB) { @@ -211,7 +211,7 @@ func clearMigrations(t *testing.T, db *pg.DB) { assert.Nil(t, err) } -func noopMigration(db orm.DB) error { +func noopMigration(_ orm.DB) error { return nil } diff --git a/rollback.go b/rollback.go index e96bdbf..40d90c9 100644 --- a/rollback.go +++ b/rollback.go @@ -55,7 +55,7 @@ func rollback(db *pg.DB) error { return fmt.Errorf("%s: %s", m.Name, err) } - _, err = db.Model(&m).Where("name = ?", m.Name).Delete() + _, err = db.Model(m).Where("name = ?", m.Name).Delete() if err != nil { return fmt.Errorf("%s: %s", m.Name, err) } @@ -65,8 +65,8 @@ func rollback(db *pg.DB) error { return nil } -func getMigrationsForBatch(migrations []migration, batch int32) []migration { - var m []migration +func getMigrationsForBatch(migrations []*migration, batch int32) []*migration { + var m []*migration for _, migration := range migrations { if migration.Batch == batch { diff --git a/rollback_test.go b/rollback_test.go index 485d7f2..e169bed 100644 --- a/rollback_test.go +++ b/rollback_test.go @@ -26,7 +26,7 @@ func TestRollback(t *testing.T) { t.Run("sorts migrations in reverse order", func(tt *testing.T) { clearMigrations(tt, db) resetMigrations(tt) - migrations = []migration{ + migrations = []*migration{ {Name: "123", Up: noopMigration, Down: noopMigration}, {Name: "456", Up: noopMigration, Down: noopMigration}, } @@ -41,7 +41,7 @@ func TestRollback(t *testing.T) { t.Run("returns an error if the migration lock is already held", func(tt *testing.T) { clearMigrations(tt, db) resetMigrations(tt) - migrations = []migration{ + migrations = []*migration{ {Name: "123", Up: noopMigration, Down: noopMigration}, {Name: "456", Up: noopMigration, Down: noopMigration}, } @@ -57,7 +57,7 @@ func TestRollback(t *testing.T) { t.Run("exits early if there aren't any migrations to rollback", func(tt *testing.T) { clearMigrations(tt, db) resetMigrations(tt) - migrations = []migration{ + migrations = []*migration{ {Name: "123", Up: noopMigration, Down: noopMigration}, {Name: "456", Up: noopMigration, Down: noopMigration}, } @@ -73,7 +73,7 @@ func TestRollback(t *testing.T) { t.Run("only rolls back the last batch", func(tt *testing.T) { clearMigrations(tt, db) resetMigrations(tt) - migrations = []migration{ + migrations = []*migration{ {Name: "123", Up: noopMigration, Down: noopMigration, Batch: 4, CompletedAt: time.Now()}, {Name: "456", Up: noopMigration, Down: noopMigration, Batch: 5, CompletedAt: time.Now()}, {Name: "789", Up: noopMigration, Down: noopMigration, Batch: 5, CompletedAt: time.Now()}, @@ -99,7 +99,7 @@ func TestRollback(t *testing.T) { t.Run(`runs "down" within a transaction if specified`, func(tt *testing.T) { clearMigrations(tt, db) resetMigrations(tt) - migrations = []migration{ + migrations = []*migration{ {Name: "123", Up: noopMigration, Down: erringMigration, DisableTransaction: false, Batch: 1, CompletedAt: time.Now()}, } @@ -115,7 +115,7 @@ func TestRollback(t *testing.T) { t.Run(`doesn't run "down" within a transaction if specified`, func(tt *testing.T) { clearMigrations(tt, db) resetMigrations(tt) - migrations = []migration{ + migrations = []*migration{ {Name: "123", Up: noopMigration, Down: erringMigration, DisableTransaction: true, Batch: 1, CompletedAt: time.Now()}, }