-
Notifications
You must be signed in to change notification settings - Fork 0
/
apply.go
44 lines (36 loc) · 921 Bytes
/
apply.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cmd
import (
"context"
"github.com/spf13/cobra"
"github.com/izumin5210/dform/app/di"
"github.com/izumin5210/dform/util/log"
)
func newApplyCommand(component di.RootComponent) *cobra.Command {
return &cobra.Command{
Use: "apply",
Short: "Apply schema",
Long: "Apply schema",
RunE: func(c *cobra.Command, _ []string) error {
var err error
ctx := context.Background()
err = component.ShowSchemaDiffService().Perform(ctx)
if err != nil {
log.Error("failed to show schema diff", "error", err)
return err
}
ok, err := component.UI().Confirm("Would you like to apply it?")
if err != nil {
log.Error("failed to confirm to apply", "error", err)
return err
}
if ok {
err = component.ApplySchemaDiffService().Perform(ctx)
if err != nil {
log.Error("failed to apply schema diff", "error", err)
return err
}
}
return nil
},
}
}