forked from polothy/pg2mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverifier.go
59 lines (49 loc) · 1.2 KB
/
verifier.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
package pg2mysql
import (
"errors"
"fmt"
)
type Verifier interface {
Verify() error
}
type verifier struct {
src, dst DB
watcher VerifierWatcher
}
func NewVerifier(src, dst DB, watcher VerifierWatcher) Verifier {
return &verifier{
src: src,
dst: dst,
watcher: watcher,
}
}
func (v *verifier) Verify() error {
srcSchema, err := BuildSchema(v.src)
if err != nil {
return fmt.Errorf("failed to build source schema: %s", err)
}
var verifyErr error
for _, table := range srcSchema.Tables {
v.watcher.TableVerificationDidStart(table.Name)
var missingRows int64
var missingIDs []string
err = EachMissingRow(v.src, v.dst, table, func(scanArgs []interface{}) error {
if colIndex, _, getColErr := table.GetColumn("id"); getColErr == nil {
if colID, ok := scanArgs[colIndex].(*interface{}); ok {
missingIDs = append(missingIDs, fmt.Sprintf("%v", *colID))
}
}
missingRows++
return nil
})
if missingRows > 0 || err != nil {
verifyErr = errors.New("verify failed")
}
if err != nil {
v.watcher.TableVerificationDidFinishWithError(table.Name, err)
continue
}
v.watcher.TableVerificationDidFinish(table.Name, missingRows, missingIDs)
}
return verifyErr
}