mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-19 08:26:23 -07:00
Add DBVERSION SQL replacer constant
This commit is contained in:
parent
65c203f464
commit
db6194a5fd
6 changed files with 11 additions and 9 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -19,7 +20,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
// GochanVersionKeyConstant is the key value used in the version table of the database to store and receive the (database) version of base gochan
|
||||
// gochanVersionKeyConstant is the key value used in the version table of the database to store and receive the (database) version of base gochan
|
||||
gochanVersionKeyConstant = "gochan"
|
||||
DatabaseVersion = 6
|
||||
UnsupportedSQLVersionMsg = `syntax error in SQL query, confirm you are using a supported driver and SQL server (error text: %s)`
|
||||
|
@ -349,6 +350,7 @@ func setupDBConn(cfg *config.SQLConfig) (db *GCDB, err error) {
|
|||
replacerArr := []string{
|
||||
"DBNAME", cfg.DBname,
|
||||
"DBPREFIX", cfg.DBprefix,
|
||||
"DBVERSION", strconv.Itoa(DatabaseVersion),
|
||||
"\n", " ",
|
||||
}
|
||||
switch cfg.DBtype {
|
||||
|
|
|
@ -91,7 +91,7 @@ func GetCompleteDatabaseVersion() (dbVersion, dbFlag int, err error) {
|
|||
}
|
||||
|
||||
// CheckAndInitializeDatabase checks the validity of the database and initialises it if it is empty
|
||||
func CheckAndInitializeDatabase(dbType string, withAdmin bool) (err error) {
|
||||
func CheckAndInitializeDatabase(dbType string, createAdmin bool) (err error) {
|
||||
dbVersion, versionFlag, err := GetCompleteDatabaseVersion()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -102,7 +102,7 @@ func CheckAndInitializeDatabase(dbType string, withAdmin bool) (err error) {
|
|||
case DBModernButBehind:
|
||||
err = ErrDeprecatedDB
|
||||
case DBClean:
|
||||
err = buildNewDatabase(dbType, withAdmin)
|
||||
err = buildNewDatabase(dbType, createAdmin)
|
||||
case DBUpToDate:
|
||||
err = nil
|
||||
case DBCorrupted:
|
||||
|
@ -116,12 +116,12 @@ func CheckAndInitializeDatabase(dbType string, withAdmin bool) (err error) {
|
|||
return err
|
||||
}
|
||||
|
||||
func buildNewDatabase(dbType string, withAdmin bool) error {
|
||||
func buildNewDatabase(dbType string, createAdmin bool) error {
|
||||
var err error
|
||||
if err = initDB("initdb_" + dbType + ".sql"); err != nil {
|
||||
return err
|
||||
}
|
||||
if withAdmin {
|
||||
if createAdmin {
|
||||
if err = createDefaultAdminIfNoStaff(); err != nil {
|
||||
return fmt.Errorf("failed creating default admin account: %w", err)
|
||||
}
|
||||
|
|
|
@ -296,4 +296,4 @@ CREATE TABLE DBPREFIXfilter_hits(
|
|||
|
||||
|
||||
INSERT INTO DBPREFIXdatabase_version(component, version)
|
||||
VALUES('gochan', 4);
|
||||
VALUES('gochan', DBVERSION);
|
||||
|
|
|
@ -288,4 +288,4 @@ CREATE TABLE DBPREFIXfilter_hits(
|
|||
);
|
||||
|
||||
INSERT INTO DBPREFIXdatabase_version(component, version)
|
||||
VALUES('gochan', 4);
|
||||
VALUES('gochan', DBVERSION);
|
||||
|
|
|
@ -288,4 +288,4 @@ CREATE TABLE DBPREFIXfilter_hits(
|
|||
);
|
||||
|
||||
INSERT INTO DBPREFIXdatabase_version(component, version)
|
||||
VALUES('gochan', 4);
|
||||
VALUES('gochan', DBVERSION);
|
||||
|
|
|
@ -288,4 +288,4 @@ CREATE TABLE DBPREFIXfilter_hits(
|
|||
);
|
||||
|
||||
INSERT INTO DBPREFIXdatabase_version(component, version)
|
||||
VALUES('gochan', 4);
|
||||
VALUES('gochan', DBVERSION);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue