-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff.go
87 lines (72 loc) · 2.24 KB
/
diff.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
Copyright 2020 somen440
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"fmt"
"github.com/gookit/color"
"github.com/somen440/gonv/converter"
"github.com/somen440/gonv/migration"
"github.com/somen440/gonv/structure"
)
// implements check
var (
_ migration.ColumnStructure = &structure.MySQL57ColumnStructure{}
_ migration.ModifiedColumnStructure = &structure.ModifiedColumnStructure{}
_ migration.ModifiedColumnStructureSet = &structure.ModifiedColumnStructureSet{}
_ migration.IndexStructure = &structure.IndexStructure{}
_ migration.TableStructure = &structure.TableStructure{}
_ migration.ViewStructure = &structure.ViewStructure{}
)
// Diff スキーマと db の diff を取る
type Diff struct {
gdo *GDO
factory *Factory
}
// NewDiff Diff object の生成
func NewDiff(conf *DBConfig) *Diff {
gdo := NewGDO(conf)
factory := &Factory{
gdo: gdo,
}
return &Diff{
gdo: gdo,
factory: factory,
}
}
// Exec 実行
func (d *Diff) Exec(beforeDbName string, schema string, ignores []string) error {
defer d.gdo.Close()
color.Info.Tips("create before database structures from db")
fmt.Println()
before, err := d.factory.CreateDatabaseStructure(beforeDbName, ignores)
if err != nil {
return err
}
fmt.Println(before)
color.Info.Tips("create after database structures from schema")
fmt.Println()
after, err := d.factory.CreateDatabaseStructureFromSchema("tmp_"+beforeDbName, schema, ignores)
if err != nil {
return err
}
fmt.Println(after)
// operate ask
color.Info.Tips("question")
o := NewOperator(before, after)
answer := o.Ask()
color.Info.Tips("migrations")
c := converter.NewConverter()
mList := c.ConvertAll(before, after, answer)
fmt.Println(mList)
return nil
}