-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff.go
47 lines (40 loc) · 1022 Bytes
/
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
package drift
import "github.com/nsogame/drift/ddl"
// Diff describes the change set between two database states
type DatabaseDiff struct {
Changes []interface{}
}
type TableDiff struct {
Changes []interface{}
}
func CalculateDatabaseDiff(left, right DatabaseState) (diff DatabaseDiff) {
diff = DatabaseDiff{}
intersection := make(map[string]TableState)
// iterate over old tables
for key, value := range left.Tables {
_, ok := right.Tables[key]
if ok {
// this table is still in the new version
intersection[key] = value
} else {
// this table got dropped!
diff.Changes = append(diff.Changes, ddl.DropTable{key})
}
}
// iterate over new tables
for key, _ := range right.Tables {
_, ok := intersection[key]
if ok {
// calculate diff of changes
} else {
// this table is new!
// TODO: column info
diff.Changes = append(diff.Changes, ddl.CreateTable{key})
}
}
return
}
func CalculateTableDiff(left, right TableState) (diff TableDiff) {
diff = TableDiff{}
return
}