mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Feat: Decide whether to do database migration based on version.lock
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
package conf
|
||||
|
||||
import (
|
||||
"Cloudreve/pkg/util"
|
||||
"cloudreve/pkg/util"
|
||||
"github.com/go-ini/ini"
|
||||
)
|
||||
|
||||
// Database 数据库
|
||||
// database 数据库
|
||||
type database struct {
|
||||
Type string
|
||||
User string
|
||||
@@ -19,6 +19,13 @@ var DatabaseConfig = &database{
|
||||
Type: "UNSET",
|
||||
}
|
||||
|
||||
// system 系统通用配置
|
||||
type system struct {
|
||||
Debug bool
|
||||
}
|
||||
|
||||
var SystemConfig = &system{}
|
||||
|
||||
var cfg *ini.File
|
||||
|
||||
// Init 初始化配置文件
|
||||
@@ -30,9 +37,16 @@ func Init(path string) {
|
||||
if err != nil {
|
||||
util.Log().Panic("无法解析配置文件 '%s': ", path, err)
|
||||
}
|
||||
err = mapSection("Database", DatabaseConfig)
|
||||
if err != nil {
|
||||
util.Log().Warning("配置文件 %s 分区解析失败: ", "Database", err)
|
||||
|
||||
sections := map[string]interface{}{
|
||||
"Database": DatabaseConfig,
|
||||
"System": SystemConfig,
|
||||
}
|
||||
for sectionName, sectionStruct := range sections {
|
||||
err = mapSection(sectionName, sectionStruct)
|
||||
if err != nil {
|
||||
util.Log().Warning("配置文件 %s 分区解析失败: ", sectionName, err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -78,5 +78,4 @@ TablePrefix = v3_`
|
||||
err = mapSection("Database", DatabaseConfig)
|
||||
asserts.NoError(err)
|
||||
|
||||
// TODO 类型不匹配测试
|
||||
}
|
||||
|
||||
11
pkg/conf/version.go
Normal file
11
pkg/conf/version.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package conf
|
||||
|
||||
import "io/ioutil"
|
||||
|
||||
const BackendVersion = string("3.0.0-b")
|
||||
|
||||
// WriteVersionLock 将当前版本信息写入 version.lock
|
||||
func WriteVersionLock() error {
|
||||
err := ioutil.WriteFile("version.lock", []byte(BackendVersion), 0644)
|
||||
return err
|
||||
}
|
||||
13
pkg/util/io.go
Normal file
13
pkg/util/io.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package util
|
||||
|
||||
import "os"
|
||||
|
||||
// Exists reports whether the named file or directory exists.
|
||||
func Exists(name string) bool {
|
||||
if _, err := os.Stat(name); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user