代码拉取完成,页面将自动刷新
package create
import (
"errors"
"io/ioutil"
"path/filepath"
"strings"
"gitee.com/go-better/dev/config/config"
"gitee.com/go-better/dev/tool/x/release"
)
func Do(env, typ, key string, dropDB bool) error {
if dropDB {
environ := config.NewEnv(env)
switch environ.Minor() {
case `production`, `staging`, `preview`:
return errors.New("drop db is forbidden under environment: " + environ.Minor())
}
}
keys, err := getKeys(key)
if err != nil {
return err
}
for _, key := range keys {
if err := create(env, typ, key, dropDB); err != nil {
return err
}
}
return nil
}
func create(env, typ, key string, dropDB bool) error {
content, err := ioutil.ReadFile(filepath.Join(release.ProjectRoot(), `sqls`, key+`.sql`))
if err != nil {
return err
}
return Creation{env: env, typ: typ, key: key, dropDB: dropDB, sql: string(content)}.do()
}
func getKeys(key string) ([]string, error) {
var keys []string
if key != "" {
keys = []string{key}
} else {
files, err := filepath.Glob(filepath.Join(release.ProjectRoot(), `sqls`, `*.sql`))
if err != nil {
return nil, err
}
for _, file := range files {
keys = append(keys, strings.TrimSuffix(filepath.Base(file), `.sql`))
}
}
return keys, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。