-
Notifications
You must be signed in to change notification settings - Fork 13
/
orm_alters.go
53 lines (44 loc) · 1006 Bytes
/
orm_alters.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
45
46
47
48
49
50
51
52
53
package scripts
import (
"context"
"github.com/coretrix/hitrix/service"
"github.com/sarulabs/di"
"github.com/coretrix/hitrix"
"github.com/fatih/color"
)
func ORMAlters() *service.Definition {
return &service.Definition{
Name: "orm-alters",
Global: true,
Script: true,
Build: func(ctn di.Container) (interface{}, error) {
return &ORMAltersScript{}, nil
},
}
}
type ORMAltersScript struct {
}
func (script *ORMAltersScript) Active() bool {
_, has := service.DI().OrmConfig()
return has
}
func (script *ORMAltersScript) Unique() bool {
return true
}
func (script *ORMAltersScript) Description() string {
return "show all MySQL schema changes"
}
func (script *ORMAltersScript) Run(_ context.Context, exit hitrix.Exit) {
ormEngine, _ := service.DI().OrmEngine()
alters := ormEngine.GetAlters()
for _, alter := range alters {
if alter.Safe {
color.Green("%s\n\n", alter.SQL)
} else {
color.Red("%s\n\n", alter.SQL)
}
}
if len(alters) > 0 {
exit.Error()
}
}