forked from vmware-archive/pg2mysql
/
validate.go
59 lines (48 loc) · 1.43 KB
/
validate.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 commands
import (
"fmt"
"github.com/pivotal-cf/pg2mysql"
)
type ValidateCommand struct{}
func (c *ValidateCommand) Execute([]string) error {
mysql := pg2mysql.NewMySQLDB(
PG2MySQL.Config.MySQL.Database,
PG2MySQL.Config.MySQL.Username,
PG2MySQL.Config.MySQL.Password,
PG2MySQL.Config.MySQL.Host,
PG2MySQL.Config.MySQL.Port,
)
err := mysql.Open()
if err != nil {
return fmt.Errorf("failed to open mysql connection: %s", err)
}
defer mysql.Close()
pg := pg2mysql.NewPostgreSQLDB(
PG2MySQL.Config.PostgreSQL.Database,
PG2MySQL.Config.PostgreSQL.Username,
PG2MySQL.Config.PostgreSQL.Password,
PG2MySQL.Config.PostgreSQL.Host,
PG2MySQL.Config.PostgreSQL.Port,
PG2MySQL.Config.PostgreSQL.SSLMode,
)
err = pg.Open()
if err != nil {
return fmt.Errorf("failed to open pg connection: %s", err)
}
defer pg.Close()
results, err := pg2mysql.NewValidator(pg, mysql).Validate()
if err != nil {
return fmt.Errorf("failed to validate: %s", err)
}
for _, result := range results {
switch {
case len(result.IncompatibleRowIDs) > 0:
fmt.Printf("found %d incompatible rows in %s with IDs %v\n", result.IncompatibleRowCount, result.TableName, result.IncompatibleRowIDs)
case result.IncompatibleRowCount > 0:
fmt.Printf("found %d incompatible rows in %s (which has no 'id' column)\n", result.IncompatibleRowCount, result.TableName)
default:
fmt.Printf("%s OK\n", result.TableName)
}
}
return nil
}