mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-10-10 07:48:14 +00:00
fix🐛: embed the seed SQL so migrate works outside the repository root
The seed scripts were read from ./config/ only, so migrating an empty database failed anywhere that directory was absent, such as a container holding just the binary and its settings. Embed them and prefer a file on disk when there is one.
This commit is contained in:
@@ -3,7 +3,7 @@ package models
|
||||
import (
|
||||
"fmt"
|
||||
"go-admin/common/global"
|
||||
"io/ioutil"
|
||||
"go-admin/config"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
@@ -61,7 +61,7 @@ func ExecSql(db *gorm.DB, filePath string) error {
|
||||
}
|
||||
|
||||
func Ioutil(filePath string) (string, error) {
|
||||
if contents, err := ioutil.ReadFile(filePath); err == nil {
|
||||
if contents, err := config.ReadSeed(filePath); err == nil {
|
||||
//因为contents是[]byte类型,直接转换成string类型后会多一行空格,需要使用strings.Replace替换换行符
|
||||
result := strings.Replace(string(contents), "\n", "", 1)
|
||||
fmt.Println("Use ioutil.ReadFile to read a file:", result)
|
||||
|
||||
Reference in New Issue
Block a user