diff --git a/.flox/.gitattributes b/.flox/.gitattributes new file mode 100644 index 0000000..bb5491e --- /dev/null +++ b/.flox/.gitattributes @@ -0,0 +1 @@ +env/manifest.lock linguist-generated=true linguist-language=JSON diff --git a/.flox/.gitignore b/.flox/.gitignore new file mode 100644 index 0000000..8d21186 --- /dev/null +++ b/.flox/.gitignore @@ -0,0 +1,5 @@ +run/ +cache/ +lib/ +log/ +!env/ diff --git a/.flox/env.json b/.flox/env.json new file mode 100644 index 0000000..9bc232f --- /dev/null +++ b/.flox/env.json @@ -0,0 +1,4 @@ +{ + "name": "pg-dba", + "version": 1 +} \ No newline at end of file diff --git a/.flox/env/manifest.lock b/.flox/env/manifest.lock new file mode 100644 index 0000000..7e0c053 --- /dev/null +++ b/.flox/env/manifest.lock @@ -0,0 +1,254 @@ +{ + "lockfile-version": 1, + "manifest": { + "version": 1, + "install": { + "go": { + "pkg-path": "go", + "version": "^1.19" + }, + "golangci-lint": { + "pkg-path": "golangci-lint" + } + }, + "hook": { + "on-activate": " # Autogenerated by Flox\n\n # Point GOENV to Flox environment cache\n export GOENV=\"$FLOX_ENV_CACHE/goenv\"\n\n # Install Go dependencies\n go get .\n\n # End autogenerated by Flox\n" + }, + "profile": {}, + "options": {} + }, + "packages": [ + { + "attr_path": "go", + "broken": false, + "derivation": "/nix/store/b4f7b08k5wnka70sax9qx3d2p1x2sfb9-go-1.24.6.drv", + "description": "Go Programming language", + "install_id": "go", + "license": "BSD-3-Clause", + "locked_url": "https://github.com/flox/nixpkgs?rev=d7600c775f877cd87b4f5a831c28aa94137377aa", + "name": "go-1.24.6", + "pname": "go", + "rev": "d7600c775f877cd87b4f5a831c28aa94137377aa", + "rev_count": 854036, + "rev_date": "2025-08-30T08:25:00Z", + "scrape_date": "2025-08-31T03:28:53.265597Z", + "stabilities": [ + "unstable" + ], + "unfree": false, + "version": "1.24.6", + "outputs_to_install": [ + "out" + ], + "outputs": { + "out": "/nix/store/rgmygksbfyy75iappxpinv0y8lxfq35x-go-1.24.6" + }, + "system": "aarch64-darwin", + "group": "toplevel", + "priority": 5 + }, + { + "attr_path": "go", + "broken": false, + "derivation": "/nix/store/x4i65glp99jc4a2cxkz1scx29s08dw05-go-1.24.6.drv", + "description": "Go Programming language", + "install_id": "go", + "license": "BSD-3-Clause", + "locked_url": "https://github.com/flox/nixpkgs?rev=d7600c775f877cd87b4f5a831c28aa94137377aa", + "name": "go-1.24.6", + "pname": "go", + "rev": "d7600c775f877cd87b4f5a831c28aa94137377aa", + "rev_count": 854036, + "rev_date": "2025-08-30T08:25:00Z", + "scrape_date": "2025-08-31T03:37:17.518582Z", + "stabilities": [ + "unstable" + ], + "unfree": false, + "version": "1.24.6", + "outputs_to_install": [ + "out" + ], + "outputs": { + "out": "/nix/store/w30rz1jlg360zk9d34ylhdvcdz19vyxh-go-1.24.6" + }, + "system": "aarch64-linux", + "group": "toplevel", + "priority": 5 + }, + { + "attr_path": "go", + "broken": false, + "derivation": "/nix/store/awngf5b7wwjyay1nlfjnk25a39f823c3-go-1.24.6.drv", + "description": "Go Programming language", + "install_id": "go", + "license": "BSD-3-Clause", + "locked_url": "https://github.com/flox/nixpkgs?rev=d7600c775f877cd87b4f5a831c28aa94137377aa", + "name": "go-1.24.6", + "pname": "go", + "rev": "d7600c775f877cd87b4f5a831c28aa94137377aa", + "rev_count": 854036, + "rev_date": "2025-08-30T08:25:00Z", + "scrape_date": "2025-08-31T03:45:26.346747Z", + "stabilities": [ + "unstable" + ], + "unfree": false, + "version": "1.24.6", + "outputs_to_install": [ + "out" + ], + "outputs": { + "out": "/nix/store/kcj6a7xghpcsg6by6kkc03s3rr2v34il-go-1.24.6" + }, + "system": "x86_64-darwin", + "group": "toplevel", + "priority": 5 + }, + { + "attr_path": "go", + "broken": false, + "derivation": "/nix/store/lz6sgami9527f9s2sh8bd8y2imv8nqqb-go-1.24.6.drv", + "description": "Go Programming language", + "install_id": "go", + "license": "BSD-3-Clause", + "locked_url": "https://github.com/flox/nixpkgs?rev=d7600c775f877cd87b4f5a831c28aa94137377aa", + "name": "go-1.24.6", + "pname": "go", + "rev": "d7600c775f877cd87b4f5a831c28aa94137377aa", + "rev_count": 854036, + "rev_date": "2025-08-30T08:25:00Z", + "scrape_date": "2025-08-31T03:52:54.344852Z", + "stabilities": [ + "unstable" + ], + "unfree": false, + "version": "1.24.6", + "outputs_to_install": [ + "out" + ], + "outputs": { + "out": "/nix/store/g026m2zmhiah7izdmmvgsq847z2sh1h1-go-1.24.6" + }, + "system": "x86_64-linux", + "group": "toplevel", + "priority": 5 + }, + { + "attr_path": "golangci-lint", + "broken": false, + "derivation": "/nix/store/gjpp09llq117kb14gza3nlgv6zvplp6x-golangci-lint-2.4.0.drv", + "description": "Fast linters Runner for Go", + "install_id": "golangci-lint", + "license": "GPL-3.0-or-later", + "locked_url": "https://github.com/flox/nixpkgs?rev=d7600c775f877cd87b4f5a831c28aa94137377aa", + "name": "golangci-lint-2.4.0", + "pname": "golangci-lint", + "rev": "d7600c775f877cd87b4f5a831c28aa94137377aa", + "rev_count": 854036, + "rev_date": "2025-08-30T08:25:00Z", + "scrape_date": "2025-08-31T03:28:53.312383Z", + "stabilities": [ + "unstable" + ], + "unfree": false, + "version": "2.4.0", + "outputs_to_install": [ + "out" + ], + "outputs": { + "out": "/nix/store/qj8ra318bgzfkrky6sw734igb4sd5kia-golangci-lint-2.4.0" + }, + "system": "aarch64-darwin", + "group": "toplevel", + "priority": 5 + }, + { + "attr_path": "golangci-lint", + "broken": false, + "derivation": "/nix/store/7bh81qxlam14pn2b8k6sz1kr0c45rhhv-golangci-lint-2.4.0.drv", + "description": "Fast linters Runner for Go", + "install_id": "golangci-lint", + "license": "GPL-3.0-or-later", + "locked_url": "https://github.com/flox/nixpkgs?rev=d7600c775f877cd87b4f5a831c28aa94137377aa", + "name": "golangci-lint-2.4.0", + "pname": "golangci-lint", + "rev": "d7600c775f877cd87b4f5a831c28aa94137377aa", + "rev_count": 854036, + "rev_date": "2025-08-30T08:25:00Z", + "scrape_date": "2025-08-31T03:37:17.598833Z", + "stabilities": [ + "unstable" + ], + "unfree": false, + "version": "2.4.0", + "outputs_to_install": [ + "out" + ], + "outputs": { + "out": "/nix/store/s4hy8cpw5ynr3dqp53bqdqq7dqnnj5pw-golangci-lint-2.4.0" + }, + "system": "aarch64-linux", + "group": "toplevel", + "priority": 5 + }, + { + "attr_path": "golangci-lint", + "broken": false, + "derivation": "/nix/store/d474ilcnjjl07kyqxzl44pkv984cjyk8-golangci-lint-2.4.0.drv", + "description": "Fast linters Runner for Go", + "install_id": "golangci-lint", + "license": "GPL-3.0-or-later", + "locked_url": "https://github.com/flox/nixpkgs?rev=d7600c775f877cd87b4f5a831c28aa94137377aa", + "name": "golangci-lint-2.4.0", + "pname": "golangci-lint", + "rev": "d7600c775f877cd87b4f5a831c28aa94137377aa", + "rev_count": 854036, + "rev_date": "2025-08-30T08:25:00Z", + "scrape_date": "2025-08-31T03:45:26.397137Z", + "stabilities": [ + "unstable" + ], + "unfree": false, + "version": "2.4.0", + "outputs_to_install": [ + "out" + ], + "outputs": { + "out": "/nix/store/2b0459163c6jz4r4sfw9z9vrfwr5bc33-golangci-lint-2.4.0" + }, + "system": "x86_64-darwin", + "group": "toplevel", + "priority": 5 + }, + { + "attr_path": "golangci-lint", + "broken": false, + "derivation": "/nix/store/akdp81hczi3ys6vja2a338vm6xb5d50c-golangci-lint-2.4.0.drv", + "description": "Fast linters Runner for Go", + "install_id": "golangci-lint", + "license": "GPL-3.0-or-later", + "locked_url": "https://github.com/flox/nixpkgs?rev=d7600c775f877cd87b4f5a831c28aa94137377aa", + "name": "golangci-lint-2.4.0", + "pname": "golangci-lint", + "rev": "d7600c775f877cd87b4f5a831c28aa94137377aa", + "rev_count": 854036, + "rev_date": "2025-08-30T08:25:00Z", + "scrape_date": "2025-08-31T03:52:54.429773Z", + "stabilities": [ + "unstable" + ], + "unfree": false, + "version": "2.4.0", + "outputs_to_install": [ + "out" + ], + "outputs": { + "out": "/nix/store/arxp4wfknba8kazch9s18dm609bis8jg-golangci-lint-2.4.0" + }, + "system": "x86_64-linux", + "group": "toplevel", + "priority": 5 + } + ] +} \ No newline at end of file diff --git a/.flox/env/manifest.toml b/.flox/env/manifest.toml new file mode 100644 index 0000000..332c6ed --- /dev/null +++ b/.flox/env/manifest.toml @@ -0,0 +1,107 @@ +## Flox Environment Manifest ----------------------------------------- +## +## _Everything_ you need to know about the _manifest_ is here: +## +## https://flox.dev/docs/reference/command-reference/manifest.toml/ +## +## ------------------------------------------------------------------- +# Flox manifest version managed by Flox CLI +version = 1 + + +## Install Packages -------------------------------------------------- +## $ flox install gum <- puts a package in [install] section below +## $ flox search gum <- search for a package +## $ flox show gum <- show all versions of a package +## ------------------------------------------------------------------- +[install] +go.pkg-path = "go" +go.version = "^1.19" +golangci-lint.pkg-path = "golangci-lint" + + +## Environment Variables --------------------------------------------- +## ... available for use in the activated environment +## as well as [hook], [profile] scripts and [services] below. +## ------------------------------------------------------------------- +[vars] +# INTRO_MESSAGE = "It's gettin' Flox in here" + + +## Activation Hook --------------------------------------------------- +## ... run by _bash_ shell when you run 'flox activate'. +## ------------------------------------------------------------------- +[hook] +on-activate = """ + # Autogenerated by Flox + + # Point GOENV to Flox environment cache + export GOENV="$FLOX_ENV_CACHE/goenv" + + # Install Go dependencies + go get . + + # End autogenerated by Flox +""" + + +## Profile script ---------------------------------------------------- +## ... sourced by _your shell_ when you run 'flox activate'. +## ------------------------------------------------------------------- +[profile] +# common = ''' +# gum style \ +# --foreground 212 --border-foreground 212 --border double \ +# --align center --width 50 --margin "1 2" --padding "2 4" \ +# $INTRO_MESSAGE +# ''' +## Shell-specific customizations such as setting aliases go here: +# bash = ... +# zsh = ... +# fish = ... + + +## Services --------------------------------------------------------- +## $ flox services start <- Starts all services +## $ flox services status <- Status of running services +## $ flox activate --start-services <- Activates & starts all +## ------------------------------------------------------------------ +[services] +# myservice.command = "python3 -m http.server" + + +## Include ---------------------------------------------------------- +## ... environments to create a composed environment +## ------------------------------------------------------------------ +[include] +# environments = [ +# { dir = "../common" } +# ] + + +## Build and publish your own packages ------------------------------ +## $ flox build +## $ flox publish +## ------------------------------------------------------------------ +[build] +# [build.myproject] +# description = "The coolest project ever" +# version = "0.0.1" +# command = """ +# mkdir -p $out/bin +# cargo build --release +# cp target/release/myproject $out/bin/myproject +# """ + + +## Other Environment Options ----------------------------------------- +[options] +# Systems that environment is compatible with +# systems = [ +# "aarch64-darwin", +# "aarch64-linux", +# "x86_64-darwin", +# "x86_64-linux", +# ] +# Uncomment to disable CUDA detection. +# cuda-detection = false diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bd5110f..ff003f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,8 +7,8 @@ jobs: strategy: matrix: go: - - '1.19' - - '1.20' + - '1.24' + - '1.25' fail-fast: false timeout-minutes: 10 env: @@ -16,15 +16,13 @@ jobs: POSTGES_HOST: "127.0.0.1" POSTGRES_USER: postgres steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 + - uses: actions/checkout@v5 + - uses: actions/setup-go@v6 with: go-version: ${{ matrix.go }} - - name: Install coverage merging tool - run: go install github.com/wadey/gocovmerge@latest - name: Start Postgres # TODO: Come back and get rid of the sleep with a health check run: | - docker-compose up -d + docker compose up -d sleep 15 - name: Seed DB env: @@ -36,14 +34,17 @@ jobs: - name: Run Tests run: make test - name: Upload Coverage - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v5 + with: + files: ./coverage.txt,./integration-coverage.txt + token: ${{ secrets.CODECOV_TOKEN }} docker-build: name: Docker Build runs-on: ubuntu-latest timeout-minutes: 10 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v5 - run: docker build -t pg-dba . docs: @@ -51,6 +52,6 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 10 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v5 - run: make docs working-directory: docs diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 90c6308..762b250 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -10,7 +10,7 @@ jobs: timeout-minutes: 10 steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v5 - name: Build Docs run: make docs working-directory: docs diff --git a/.github/workflows/golangci.yml b/.github/workflows/golangci.yml index 7e3bf96..11336d7 100644 --- a/.github/workflows/golangci.yml +++ b/.github/workflows/golangci.yml @@ -6,8 +6,8 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 15 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v5 - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v8 with: - version: v1.51.2 + version: v2.4.0 diff --git a/Dockerfile b/Dockerfile index 54b79d5..40c8ac5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.20-alpine as builder +FROM golang:1.24.6-alpine AS builder RUN apk add --no-cache git WORKDIR /pg-dba COPY . . diff --git a/Makefile b/Makefile index dc4995d..408e121 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ clean: rm -rf integration-coverage.txt compose-up: - docker-compose up -d + docker compose up -d integration: SSL_MODE=disable go test -v -tags=integration ./pkg/dba/... @@ -17,7 +17,6 @@ docker-image: # Run the unit and integration tests and combine them. test: unit-tests integration-tests - gocovmerge coverage.txt integration-coverage.txt > coverage.txt unit-tests: go test -v -coverprofile=coverage.txt -covermode=atomic ./... diff --git a/docker-compose.yml b/docker-compose.yml index baa4976..b563e09 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3' services: db: - image: postgres:12 + image: postgres:17 environment: POSTGRES_HOST_AUTH_METHOD: trust ports: diff --git a/go.mod b/go.mod index 4452c8f..050c8e5 100644 --- a/go.mod +++ b/go.mod @@ -1,17 +1,17 @@ module github.com/jonstacks/pg-dba -go 1.19 +go 1.24 require ( github.com/joho/godotenv v1.5.1 - github.com/lib/pq v1.10.7 - github.com/sirupsen/logrus v1.9.0 - github.com/stretchr/testify v1.7.0 + github.com/lib/pq v1.10.9 + github.com/sirupsen/logrus v1.9.3 + github.com/stretchr/testify v1.11.1 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/sys v0.5.0 // indirect - gopkg.in/yaml.v3 v3.0.0 // indirect + golang.org/x/sys v0.35.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index a830cc8..477e214 100644 --- a/go.sum +++ b/go.sum @@ -3,20 +3,21 @@ 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= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= -github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= -github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= +github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= -github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI= +golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA= -gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 39c7c0b..f05d236 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -10,9 +10,9 @@ import ( ) func withEnvSet(key, value string, f func(key string)) { - os.Setenv(key, value) + _ = os.Setenv(key, value) f(key) - os.Unsetenv(key) + _ = os.Unsetenv(key) } func testAllBoolVariable(t *testing.T, key string, defaultValue bool, f func() bool) { diff --git a/pkg/dba/dba.go b/pkg/dba/dba.go index be7ccb3..0357ff7 100644 --- a/pkg/dba/dba.go +++ b/pkg/dba/dba.go @@ -83,7 +83,7 @@ func (dba *DBA) Run() error { if err != nil { return err } - defer dba.db.Close() + defer func() { _ = dba.db.Close() }() if err = dba.db.Ping(); err != nil { return err