34 lines
567 B
Go
34 lines
567 B
Go
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
|
|
},
|
|
}
|