forked from hidu/mysql-schema-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alter.go
58 lines (50 loc) · 994 Bytes
/
alter.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
package internal
import (
"fmt"
"strings"
)
type AlterType int
const (
AlterTypeNo AlterType = 0
AlterTypeCreate = 1
AlterTypeDrop = 2
AlterTypeAlter = 3
)
func (at AlterType) String() string {
switch at {
case AlterTypeNo:
return "not_change"
case AlterTypeCreate:
return "create"
case AlterTypeDrop:
return "drop"
case AlterTypeAlter:
return "alter"
default:
return "unknow"
}
}
func NewAlterData(tableName string) *TableAlterData {
return &TableAlterData{
Table: tableName,
Type: AlterTypeNo,
}
}
// TableAlterData 表的变更情况
type TableAlterData struct {
Table string
Type AlterType
SQL string
SchemaDiff *SchemaDiff
}
func (ta *TableAlterData) String() string {
relationTables := ta.SchemaDiff.RelationTables()
fmtStr := `
-- Table : %s
-- Type : %s
-- RealtionTables : %s
-- SQL :
%s
`
return fmt.Sprintf(fmtStr, ta.Table, ta.Type, strings.Join(relationTables, ","), ta.SQL)
}