-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(timestamps): adding timestamps to the version table (#65)
* adding timestamps to the version table * Adding status cmd
- Loading branch information
1 parent
27a7adb
commit 915436b
Showing
951 changed files
with
363,436 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.