Merge pull request #51 from Jinnrry/bugfix-init

bug fix
This commit is contained in:
木木的木头
2023-11-23 14:17:59 +08:00
committed by GitHub
2 changed files with 12 additions and 4 deletions
+3
View File
@@ -91,6 +91,9 @@ func Init() {
if e != nil {
panic(e)
}
if len(i) == 0 || strings.TrimSpace(string(i)) == "" {
return nil
}
if strings.Contains(path, "data") {
Instance.TablesInitData[tableName] = string(i)
} else {
+9 -4
View File
@@ -68,6 +68,9 @@ func checkTable() {
}
for tableName, createSQL := range config.Instance.Tables {
if createSQL == "" {
continue
}
if _, ok := existTable[tableName]; !ok {
_, err = Instance.Exec(createSQL)
log.Infof("Create Table: %s", createSQL)
@@ -76,10 +79,12 @@ func checkTable() {
}
if initData, ok := config.Instance.TablesInitData[tableName]; ok {
_, err = Instance.Exec(initData)
log.Infof("Init Table: %s", initData)
if err != nil {
panic(err)
if initData != "" {
_, err = Instance.Exec(initData)
log.Infof("Init Table: %s", initData)
if err != nil {
panic(err)
}
}
}