fix: Improve setup check logic and logging for system initialization
Some checks failed
Publish Docker image (amd64) / Push Docker image to multiple registries (push) Has been cancelled
Publish Docker image (arm64) / Push Docker image to multiple registries (push) Has been cancelled
Linux Release / release (push) Has been cancelled
macOS Release / release (push) Has been cancelled
Windows Release / release (push) Has been cancelled

This commit is contained in:
CaIon 2025-04-04 21:27:24 +08:00
parent ad7a64e585
commit eca18ce25c

View File

@ -57,22 +57,29 @@ func createRootAccountIfNeed() error {
} }
func checkSetup() { func checkSetup() {
if GetSetup() == nil { setup := GetSetup()
if setup == nil {
// No setup record exists, check if we have a root user
if RootUserExists() { if RootUserExists() {
common.SysLog("system is not initialized, but root user exists") common.SysLog("system is not initialized, but root user exists")
// Create setup record // Create setup record
setup := Setup{ newSetup := Setup{
Version: common.Version, Version: common.Version,
InitializedAt: time.Now().Unix(), InitializedAt: time.Now().Unix(),
} }
err := DB.Create(&setup).Error err := DB.Create(&newSetup).Error
if err != nil { if err != nil {
common.SysLog("failed to create setup record: " + err.Error()) common.SysLog("failed to create setup record: " + err.Error())
} }
constant.Setup = true constant.Setup = true
} else { } else {
common.SysLog("system is not initialized and no root user exists")
constant.Setup = false constant.Setup = false
} }
} else {
// Setup record exists, system is initialized
common.SysLog("system is already initialized at: " + time.Unix(setup.InitializedAt, 0).String())
constant.Setup = true
} }
} }