fix: 数据持久化到/app/data目录,简化部署配置
- 配置文件和SQLite数据库存储在/app/data - Docker volume持久化数据 - 无需预设环境变量,安装向导自动配置
This commit is contained in:
@@ -80,9 +80,9 @@ func handleTestDatabase(c *gin.Context) {
|
||||
}
|
||||
|
||||
if req.DbType == "sqlite" {
|
||||
dbPath := "verification_platform.db"
|
||||
absPath, _ := filepath.Abs(dbPath)
|
||||
testDB, err := gorm.Open(sqlite.Open(absPath), &gorm.Config{
|
||||
dataDir := config.GetDataDir()
|
||||
dbPath := filepath.Join(dataDir, "verification_platform.db")
|
||||
testDB, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Silent),
|
||||
})
|
||||
if err != nil {
|
||||
@@ -167,9 +167,9 @@ func handleSetup(c *gin.Context) {
|
||||
var err error
|
||||
|
||||
if req.DbType == "sqlite" {
|
||||
dbPath := "verification_platform.db"
|
||||
absPath, _ := filepath.Abs(dbPath)
|
||||
newDB, err = gorm.Open(sqlite.Open(absPath), &gorm.Config{
|
||||
dataDir := config.GetDataDir()
|
||||
dbPath := filepath.Join(dataDir, "verification_platform.db")
|
||||
newDB, err = gorm.Open(sqlite.Open(dbPath), &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Silent),
|
||||
DisableForeignKeyConstraintWhenMigrating: true,
|
||||
})
|
||||
@@ -241,6 +241,11 @@ func handleSetup(c *gin.Context) {
|
||||
}
|
||||
|
||||
func checkConfigFile() bool {
|
||||
dataDir := config.GetDataDir()
|
||||
configPath := filepath.Join(dataDir, "config.yaml")
|
||||
if _, err := os.Stat(configPath); err == nil {
|
||||
return true
|
||||
}
|
||||
paths := []string{"config.yaml", "./config/config.yaml"}
|
||||
for _, p := range paths {
|
||||
if _, err := os.Stat(p); err == nil {
|
||||
@@ -338,7 +343,9 @@ func generateConfigFile(dbType string, req SetupRequest, jwtSecret string) strin
|
||||
}
|
||||
|
||||
func saveConfigFile(content string) error {
|
||||
file, err := os.Create("config.yaml")
|
||||
dataDir := config.GetDataDir()
|
||||
configPath := filepath.Join(dataDir, "config.yaml")
|
||||
file, err := os.Create(configPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user