Skip to content

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
efritz committed Sep 13, 2024
1 parent 1de3c0d commit 6ebada5
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 8 deletions.
1 change: 0 additions & 1 deletion cmd/migrate/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
var createCmd = &cobra.Command{
Use: "create [flags] 'migration name'",
Short: "Create a new schema migration",
Long: `TODO`,
Args: cobra.ExactArgs(1),
RunE: create,
}
Expand Down
1 change: 0 additions & 1 deletion cmd/migrate/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
var describeCmd = &cobra.Command{
Use: "describe",
Short: "Describe the current database schema",
Long: `TODO`,
RunE: describe,
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/migrate/drift.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import (

var driftCmd = &cobra.Command{
Use: "drift",
Short: "TODO",
Long: `TODO`,
Short: "Compare the current database schema against the expected schema",
RunE: drift,
}

Expand Down
8 changes: 6 additions & 2 deletions cmd/migrate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func main() {
var rootCmd = &cobra.Command{
Use: "migrate",
Short: "Manage and execute Postgres schema migrations",
Long: `TODO`,
}

var (
Expand All @@ -27,7 +26,12 @@ var (
)

func init() {
rootCmd.PersistentFlags().StringVarP(&migrationDirectory, "dir", "d", "migrations", `TODO`)
rootCmd.PersistentFlags().StringVarP(
&migrationDirectory,
"dir", "d",
"migrations",
"The directory where schema migrations are defined",
)
}

func dial() (pgutil.DB, error) {
Expand Down
1 change: 0 additions & 1 deletion cmd/migrate/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
var stateCmd = &cobra.Command{
Use: "state",
Short: "Display the current state of the database schema",
Long: `TODO`,
RunE: state,
}

Expand Down
34 changes: 34 additions & 0 deletions cmd/migrate/undo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"context"
"fmt"
"strconv"

"github.com/spf13/cobra"
)

var undoCmd = &cobra.Command{
Use: "undo [migration_id]",
Short: "Undo migrations up to and including the specified migration ID",
Args: cobra.ExactArgs(1),
RunE: undo,
}

func init() {
rootCmd.AddCommand(undoCmd)
}

func undo(cmd *cobra.Command, args []string) error {
migrationID, err := strconv.Atoi(args[0])
if err != nil {
return fmt.Errorf("invalid migration ID: %v", err)
}

runner, err := runner()
if err != nil {
return err
}

return runner.Undo(context.Background(), migrationID)
}
1 change: 0 additions & 1 deletion cmd/migrate/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
var upCmd = &cobra.Command{
Use: "up",
Short: "Run all schema migrations",
Long: `TODO`,
RunE: up,
}

Expand Down

0 comments on commit 6ebada5

Please sign in to comment.