1 Star 0 Fork 76

paul008/mysql-schema-sync

forked from hidu/mysql-schema-sync 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 1.69 KB
一键复制 编辑 原始数据 按行查看 历史
hidu 提交于 2015-11-08 15:56 . v0.3 add foreign support
package main
import (
"flag"
"fmt"
"github.com/hidu/mysql-schema-sync/internal"
"log"
"os"
"strings"
)
var configPath = flag.String("conf", "./config.json", "json config file path")
var sync = flag.Bool("sync", false, "sync shcema change to dest db")
var drop = flag.Bool("drop", false, "drop fields,index,foreign key")
var source = flag.String("source", "", "mysql dsn source,eg: test@(10.10.0.1:3306)/test\n\twhen it is not empty ignore [-conf] param")
var dest = flag.String("dest", "", "mysql dsn dest,eg test@(127.0.0.1:3306)/imis")
var tables = flag.String("tables", "", "table names to check\n\teg : product_base,order_*")
var mailTo = flag.String("mail_to", "", "overwrite config's email.to")
func init() {
log.SetFlags(log.Lshortfile | log.Ldate)
df := flag.Usage
flag.Usage = func() {
df()
fmt.Fprintln(os.Stderr, "")
fmt.Fprintln(os.Stderr, "mysql schema sync tools "+internal.Version)
fmt.Fprintln(os.Stderr, internal.AppURL+"\n")
}
}
var cfg *internal.Config
func main() {
flag.Parse()
if *source == "" {
cfg = internal.LoadConfig(*configPath)
} else {
cfg = new(internal.Config)
cfg.SourceDSN = *source
cfg.DestDSN = *dest
}
cfg.Sync = *sync
cfg.Drop = *drop
if *mailTo != "" && cfg.Email != nil {
cfg.Email.To = *mailTo
}
if cfg.Tables == nil {
cfg.Tables = []string{}
}
if *tables != "" {
_ts := strings.Split(*tables, ",")
for _, _name := range _ts {
_name = strings.TrimSpace(_name)
if _name != "" {
cfg.Tables = append(cfg.Tables, _name)
}
}
}
defer (func() {
if err := recover(); err != nil {
log.Println(err)
cfg.SendMailFail(fmt.Sprintf("%s", err))
log.Fatalln("exit")
}
})()
cfg.Check()
internal.CheckSchemaDiff(cfg)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/paul008/mysql-schema-sync.git
git@gitee.com:paul008/mysql-schema-sync.git
paul008
mysql-schema-sync
mysql-schema-sync
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385