()
| 88 | } |
| 89 | |
| 90 | func CheckSetup() { |
| 91 | setup := GetSetup() |
| 92 | if setup == nil { |
| 93 | // No setup record exists, check if we have a root user |
| 94 | if RootUserExists() { |
| 95 | common.SysLog("system is not initialized, but root user exists") |
| 96 | // Create setup record |
| 97 | newSetup := Setup{ |
| 98 | Version: common.Version, |
| 99 | InitializedAt: time.Now().Unix(), |
| 100 | } |
| 101 | err := DB.Create(&newSetup).Error |
| 102 | if err != nil { |
| 103 | common.SysLog("failed to create setup record: " + err.Error()) |
| 104 | } |
| 105 | constant.Setup = true |
| 106 | } else { |
| 107 | common.SysLog("system is not initialized and no root user exists") |
| 108 | constant.Setup = false |
| 109 | } |
| 110 | } else { |
| 111 | // Setup record exists, system is initialized |
| 112 | common.SysLog("system is already initialized at: " + time.Unix(setup.InitializedAt, 0).String()) |
| 113 | constant.Setup = true |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | func chooseDB(envName string, isLog bool) (*gorm.DB, error) { |
| 118 | defer func() { |
no test coverage detected