Skip to content

Commit

Permalink
Adding status cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacobbrewer1 committed Jan 18, 2025
1 parent 18b5f8f commit a5f56c3
Show file tree
Hide file tree
Showing 263 changed files with 74,585 additions and 0 deletions.
35 changes: 35 additions & 0 deletions cmd_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ package main
import (
"context"
"flag"
"fmt"
"log/slog"
"os"

"github.com/google/subcommands"
"github.com/jacobbrewer1/goschema/pkg/migrations"
"github.com/pterm/pterm"
)

type statusCmd struct{}
Expand All @@ -26,5 +31,35 @@ func (c *statusCmd) Usage() string {
func (c *statusCmd) SetFlags(f *flag.FlagSet) {}

func (c *statusCmd) Execute(_ context.Context, _ *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
if e := os.Getenv(migrations.DbEnvVar); e == "" {
slog.Error(fmt.Sprintf("Environment variable %s is not set", migrations.DbEnvVar))
return subcommands.ExitFailure
}

db, err := migrations.ConnectDB()
if err != nil {
slog.Error("Error connecting to the database", slog.String("error", err.Error()))
return subcommands.ExitFailure
}

versions, err := migrations.NewVersioning(db, "", 0).GetStatus()
if err != nil {
slog.Error("Error getting the status", slog.String("error", err.Error()))
return subcommands.ExitFailure
}

tableDataStr := make([][]string, 0)
tableDataStr = append(tableDataStr, []string{"Version", "Current", "Created At"})
for _, v := range versions {
tableDataStr = append(tableDataStr, []string{v.Version, fmt.Sprintf("%t", v.IsCurrent == 1), v.CreatedAt.String()})
}

var tableData pterm.TableData = tableDataStr

if err := pterm.DefaultTable.WithHasHeader().WithBoxed().WithData(tableData).Render(); err != nil {
slog.Error("Error rendering table", slog.String("error", err.Error()))
return subcommands.ExitFailure
}

return subcommands.ExitSuccess
}
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,25 @@ require (
github.com/jmoiron/sqlx v1.4.0
github.com/pingcap/tidb/pkg/parser v0.0.0-20241220080229-acba0cd1e2b0
github.com/prometheus/client_golang v1.20.5
github.com/pterm/pterm v0.12.80
github.com/stretchr/testify v1.10.0
)

require (
atomicgo.dev/cursor v0.2.0 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
atomicgo.dev/schedule v0.1.0 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/go-jose/go-jose/v4 v4.0.1 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
Expand All @@ -41,6 +47,8 @@ require (
github.com/hashicorp/vault/api/auth/kubernetes v0.8.0 // indirect
github.com/hashicorp/vault/api/auth/userpass v0.8.0 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
Expand All @@ -53,15 +61,18 @@ require (
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.6.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
Expand Down
89 changes: 89 additions & 0 deletions go.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func main() {
subcommands.Register(new(generateCmd), "")
subcommands.Register(new(createCmd), "")
subcommands.Register(new(migrateCmd), "")
subcommands.Register(new(statusCmd), "")

flag.Parse()

Expand Down
32 changes: 32 additions & 0 deletions pkg/migrations/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package migrations

import (
"fmt"

"github.com/jacobbrewer1/goschema/pkg/models"
)

func (v *versioning) GetStatus() ([]*models.GoschemaMigrationVersion, error) {
sqlStmt := `
SELECT version
FROM goschema_migration_version
ORDER BY created_at DESC;
`

ids := make([]string, 0)
if err := v.db.Select(&ids, sqlStmt); err != nil {
return nil, fmt.Errorf("get status ids: %w", err)
}

versions := make([]*models.GoschemaMigrationVersion, len(ids))
for i, id := range ids {
ver, err := models.GoschemaMigrationVersionByVersion(v.db, id)
if err != nil {
return nil, fmt.Errorf("get status version by version: %w", err)
}

versions[i] = ver
}

return versions, nil
}
1 change: 1 addition & 0 deletions pkg/migrations/versioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
type Versioning interface {
MigrateUp() error
MigrateDown() error
GetStatus() ([]*models.GoschemaMigrationVersion, error)
}

type versioning struct {
Expand Down
31 changes: 31 additions & 0 deletions vendor/atomicgo.dev/cursor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
### Go template
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
vendor/

### IntelliJ
.idea
*.iml
out
gen

### VisualStudioCode
.vscode
*.code-workspace

### macOS
# General
.DS_Store
experimenting
99 changes: 99 additions & 0 deletions vendor/atomicgo.dev/cursor/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
linters-settings:
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport
- ifElseChain
- octalLiteral
- whyNoLint
- wrapperFunc
- exitAfterDefer
- hugeParam
- ptrToRefParam
- paramTypeCombine
- unnamedResult
linters:
disable-all: true
enable:
# default linters
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
# additional linters
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- decorder
- dupl
- durationcheck
- errchkjson
- errname
- errorlint
- exhaustive
- exhaustruct
- exportloopref
- forcetypeassert
- gocheckcompilerdirectives
- gocritic
- godot
- godox
- goerr113
- gofmt
- goprintffuncname
- gosec
- gosmopolitan
- importas
- ireturn
- nakedret
- nestif
- nilerr
- nilnil
- prealloc
- predeclared
- revive
- rowserrcheck
- tagalign
- tenv
- thelper
- tparallel
- unconvert
- unparam
- usestdlibvars
- wastedassign
- whitespace
- wrapcheck
- wsl
- gocyclo
- misspell
issues:
include:
- EXC0012
- EXC0014
exclude-rules:
- path: _test\.go
linters:
- gocyclo
- errcheck
- dupl
- gosec
- gocritic
- linters:
- gocritic
text: "unnecessaryDefer:"
- linters:
- gocritic
text: "preferDecodeRune:"
service:
golangci-lint-version: 1.53.x
20 changes: 20 additions & 0 deletions vendor/atomicgo.dev/cursor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<a name="unreleased"></a>
## [Unreleased]


<a name="v0.0.1"></a>
## v0.0.1 - 2021-05-09
### Features
- implement `Area`
- add `ClearLinesUp` and `ClearLinesDown`
- implement cross-platform support
- implement cursor functions

### Bug Fixes
- height can no longer be negative on non windows systems

### Code Refactoring
- remove debug code


[Unreleased]: https://github.com/MarvinJWendt/testza/compare/v0.0.1...HEAD
21 changes: 21 additions & 0 deletions vendor/atomicgo.dev/cursor/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Marvin Wendt (MarvinJWendt)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit a5f56c3

Please sign in to comment.