Init: bootstrap go module with basic framework
This commit is contained in:
33
cmd/migrates/rollback.go
Normal file
33
cmd/migrates/rollback.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package migrates
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var rollbackCmd = &cobra.Command{
|
||||
Use: "rollback",
|
||||
Short: "Rollback from last migration group",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
ctx := cmd.Context()
|
||||
|
||||
if err := migrator.Lock(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
defer migrator.Unlock(ctx)
|
||||
|
||||
group, err := migrator.Rollback(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if group.IsZero() {
|
||||
fmt.Printf("there are no groups to roll back\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Printf("roll back from %s\n", group)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user