test passed
This commit is contained in:
parent
4f1939c7ac
commit
711823fc31
6
common/conf.sample
Normal file
6
common/conf.sample
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
mysql:
|
||||||
|
host: 'xxx'
|
||||||
|
user: 'xxx'
|
||||||
|
password: 'xxx'
|
||||||
|
database: 'xxx'
|
||||||
|
port: '3306'
|
||||||
35
examples/data.go
Normal file
35
examples/data.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package examples
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/yedf/dtm/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RunSqlScript(mysql map[string]string, script string) {
|
||||||
|
conf := map[string]string{}
|
||||||
|
common.MustRemarshal(mysql, &conf)
|
||||||
|
conf["database"] = ""
|
||||||
|
db, con := common.DbAlone(conf)
|
||||||
|
defer func() { con.Close() }()
|
||||||
|
content, err := ioutil.ReadFile(script)
|
||||||
|
if err != nil {
|
||||||
|
e2p(err)
|
||||||
|
}
|
||||||
|
sqls := strings.Split(string(content), ";")
|
||||||
|
for _, sql := range sqls {
|
||||||
|
s := strings.TrimSpace(sql)
|
||||||
|
if strings.Contains(strings.ToLower(s), "drop") || s == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
logrus.Printf("executing: '%s'", s)
|
||||||
|
db.Must().Exec(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func PopulateMysql() {
|
||||||
|
common.InitApp(common.GetCurrentPath(), &Config)
|
||||||
|
RunSqlScript(Config.Mysql, common.GetCurrentPath()+"/examples.sql")
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user