|
|
|
@ -0,0 +1,50 @@
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bufio"
|
|
|
|
|
"dsSzxy/Utils/FileUtil"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io"
|
|
|
|
|
"log"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
workingPath := "D:\\Work\\dsMin\\dsSzxy\\Tools"
|
|
|
|
|
//1、按行读取文件内容
|
|
|
|
|
f, err := os.Open(workingPath + "\\loader_table_list.txt")
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
defer f.Close()
|
|
|
|
|
rd := bufio.NewReader(f)
|
|
|
|
|
for {
|
|
|
|
|
line, err := rd.ReadString('\n') //以'\n'为结束符读入一行
|
|
|
|
|
if err != nil || io.EOF == err {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
fmt.Println(line)
|
|
|
|
|
line = strings.Replace(line, "\r\n", "", -1)
|
|
|
|
|
//2、生成mysql2pg需要的文本文件
|
|
|
|
|
tableNameFile := workingPath + "\\" + line + ".txt"
|
|
|
|
|
FileUtil.WriteFileContent(tableNameFile, line)
|
|
|
|
|
//3、调用mysql2pg生成建表语句
|
|
|
|
|
command := "mysql2pg -d -l " + tableNameFile + " >> sql_" + tableNameFile
|
|
|
|
|
cmd := exec.Command("/bin/bash", "-c", command)
|
|
|
|
|
bytes, err := cmd.Output()
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Println(err)
|
|
|
|
|
}
|
|
|
|
|
resp := string(bytes)
|
|
|
|
|
log.Println(resp)
|
|
|
|
|
//4、替换主键名称,小写化
|
|
|
|
|
|
|
|
|
|
//5、删除临时表
|
|
|
|
|
os.Remove(tableNameFile)
|
|
|
|
|
//5、将建表sql+注释整理出来
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println("恭喜,全部实体表成功完成!")
|
|
|
|
|
}
|