-
Notifications
You must be signed in to change notification settings - Fork 13
/
orm_alters.go
56 lines (43 loc) · 1016 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
54
55
56
package scripts
import (
"context"
"github.com/fatih/color"
"github.com/sarulabs/di"
"github.com/coretrix/hitrix/service"
"github.com/coretrix/hitrix/service/component/app"
)
func ORMAlters() *service.DefinitionGlobal {
return &service.DefinitionGlobal{
Name: "orm-alters",
Script: true,
Build: func(ctn di.Container) (interface{}, error) {
return &ORMAltersScript{}, nil
},
}
}
type ORMAltersScript struct {
}
func (script *ORMAltersScript) Active() bool {
_ = service.DI().OrmConfig()
return true
}
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 app.IExit) {
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()
}
}