Skip to content

Commit

Permalink
feat(timestamps): adding timestamps to the version table (#65)
Browse files Browse the repository at this point in the history
* adding timestamps to the version table

* Adding status cmd
  • Loading branch information
Jacobbrewer1 authored Jan 18, 2025
1 parent 27a7adb commit 915436b
Show file tree
Hide file tree
Showing 951 changed files with 363,436 additions and 52 deletions.
65 changes: 65 additions & 0 deletions cmd_status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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{}

func (c *statusCmd) Name() string {
return "status"
}

func (c *statusCmd) Synopsis() string {
return "Print the status of the database migrations."
}

func (c *statusCmd) Usage() string {
return `status:
Print the status of the database migrations.
`
}

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
}
24 changes: 21 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,30 @@ require (
github.com/google/subcommands v1.2.0
github.com/hashicorp/vault/api v1.15.0
github.com/huandu/xstrings v1.5.0
github.com/jacobbrewer1/patcher v0.1.14
github.com/jacobbrewer1/vaulty v0.1.6
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/go-cmp v0.6.0 // 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 @@ -38,26 +47,35 @@ 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/kr/pretty v0.3.1 // 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
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb // indirect
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 // indirect
github.com/pingcap/log v1.1.1-0.20230317032135-a0d097d16e22 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
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
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 915436b

Please sign in to comment.