mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-12 18:46:24 -07:00
Add functions to stop double initialisation
This commit is contained in:
parent
1b3314499d
commit
4deb256b67
2 changed files with 56 additions and 25 deletions
|
@ -52,34 +52,38 @@ func ConnectToDB(host string, dbType string, dbName string, username string, pas
|
|||
gclog.Print(fatalSQLFlags, "Failed to connect to the database: ", err.Error())
|
||||
}
|
||||
|
||||
if err = initDB("initdb_" + dbType + ".sql"); err != nil {
|
||||
gclog.Print(fatalSQLFlags, "Failed initializing DB: ", err.Error())
|
||||
}
|
||||
//TODO TEMP
|
||||
alreadyPopulated, err := DoesDatabaseVersionExist()
|
||||
if !alreadyPopulated {
|
||||
|
||||
// Create generic "Main" section if one doesn't already exist
|
||||
if _, err = GetOrCreateDefaultSectionID(); err != nil {
|
||||
gclog.Print(fatalSQLFlags, "Failed initializing DB: ", err.Error())
|
||||
}
|
||||
//TODO fix new install thing once it works with existing database
|
||||
// var sqlVersionStr string
|
||||
// isNewInstall := false
|
||||
// if err = queryRowSQL("SELECT value FROM DBPREFIXinfo WHERE name = 'version'",
|
||||
// []interface{}{}, []interface{}{&sqlVersionStr},
|
||||
// ); err == sql.ErrNoRows {
|
||||
// isNewInstall = true
|
||||
// } else if err != nil {
|
||||
// gclog.Print(lErrorLog|lStdLog|lFatal, "Failed initializing DB: ", err.Error())
|
||||
// }
|
||||
if err = initDB("initdb_" + dbType + ".sql"); err != nil {
|
||||
gclog.Print(fatalSQLFlags, "Failed initializing DB: ", err.Error())
|
||||
}
|
||||
|
||||
err = CreateDefaultBoardIfNoneExist()
|
||||
if err != nil {
|
||||
gclog.Print(fatalSQLFlags, "Failed creating default board: ", err.Error())
|
||||
//TODO fix new install thing once it works with existing database
|
||||
// var sqlVersionStr string
|
||||
// isNewInstall := false
|
||||
// if err = queryRowSQL("SELECT value FROM DBPREFIXinfo WHERE name = 'version'",
|
||||
// []interface{}{}, []interface{}{&sqlVersionStr},
|
||||
// ); err == sql.ErrNoRows {
|
||||
// isNewInstall = true
|
||||
// } else if err != nil {
|
||||
// gclog.Print(lErrorLog|lStdLog|lFatal, "Failed initializing DB: ", err.Error())
|
||||
// }
|
||||
|
||||
err = CreateDefaultBoardIfNoneExist()
|
||||
if err != nil {
|
||||
gclog.Print(fatalSQLFlags, "Failed creating default board: ", err.Error())
|
||||
}
|
||||
err = CreateDefaultAdminIfNoStaff()
|
||||
if err != nil {
|
||||
gclog.Print(fatalSQLFlags, "Failed creating default admin account: ", err.Error())
|
||||
}
|
||||
//fix versioning thing
|
||||
} else {
|
||||
gclog.Print(gclog.LStdLog, "Database already populated")
|
||||
}
|
||||
err = CreateDefaultAdminIfNoStaff()
|
||||
if err != nil {
|
||||
gclog.Print(fatalSQLFlags, "Failed creating default admin account: ", err.Error())
|
||||
}
|
||||
//fix versioning thing
|
||||
//END TEMP
|
||||
}
|
||||
|
||||
func initDB(initFile string) error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue