flyway to go
自动管理 change sql
#使用 使用 go 命令, 下载当前的源码
go get github.com/poemp/goway
这样就好了, 可以使用了
需要参数配置
type WayConfigure struct {
Host string
Port string
User string
Password string
DbName string
SearchPath string
Table string
Path string
}
#使用方法 首先需要做配置, 请在启动的时候重写
inter.DefaultTableDataSource = func() inter.WayConfigure {
return inter.WayConfigure{
Host: host,
Port: port,
User: user,
Password: password,
DbName: dbName,
SearchPath: searchPath,
Table: table,
Path: path,
}
}
然后, 调用手动执行
way.Flyway{}.Execu()
import (
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
"github.com/poemp/goway/inter"
"github.com/poemp/goway/way"
)
const (
host = "127.0.0.1"
port = "5432"
user = "postgres"
password = "123456"
dbName = "vs_voice"
searchPath = "public"
table = "schema_history"
path = "sql"
)
func init() {
inter.DefaultTableDataSource = func() inter.WayConfigure {
return inter.WayConfigure{
Host: host,
Port: port,
User: user,
Password: password,
DbName: dbName,
SearchPath: searchPath,
Table: table,
Path: path,
}
}
way.Flyway{}.Execu()
MigrateDB()
}
这样就可以了, 最后, 可以在csdn上查看
https://blog.csdn.net/poem_2010/article/details/86241999
Version | Tag | Published |
---|---|---|
v0.0.0-20190510021839-ca714e85ec46 | 3yrs ago |