mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-21 23:22:34 +01:00
revert: remove SQLite support
An MMO server without multiplayer defeats the purpose. PostgreSQL is the right choice and Docker Compose already solves the setup pain. This reverts the common/db wrapper, SQLite schema, config Driver field, modernc.org/sqlite dependency, and all repo type changes while keeping the dashboard, wizard, and CI improvements from the previous commit.
This commit is contained in:
54
main.go
54
main.go
@@ -25,7 +25,6 @@ import (
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/lib/pq"
|
||||
"go.uber.org/zap"
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
|
||||
// Temporary DB auto clean on startup for quick development & testing.
|
||||
@@ -109,7 +108,7 @@ func main() {
|
||||
logger.Info(fmt.Sprintf("Starting Erupe (9.3b-%s)", Commit()))
|
||||
logger.Info(fmt.Sprintf("Client Mode: %s (%d)", config.ClientMode, config.RealClientMode))
|
||||
|
||||
if config.Database.Driver != "sqlite" && config.Database.Password == "" {
|
||||
if config.Database.Password == "" {
|
||||
preventClose(config, "Database password is blank")
|
||||
}
|
||||
|
||||
@@ -137,38 +136,19 @@ func main() {
|
||||
logger.Info("Discord: Disabled")
|
||||
}
|
||||
|
||||
// Create the DB pool.
|
||||
var db *sqlx.DB
|
||||
if config.Database.Driver == "sqlite" {
|
||||
dbPath := config.Database.Database
|
||||
if dbPath == "" || dbPath == "erupe" {
|
||||
dbPath = "erupe.db"
|
||||
}
|
||||
db, err = sqlx.Open("sqlite", dbPath+"?_pragma=journal_mode(WAL)&_pragma=foreign_keys(1)")
|
||||
if err != nil {
|
||||
preventClose(config, fmt.Sprintf("Database: Failed to open SQLite %s, %s", dbPath, err.Error()))
|
||||
}
|
||||
// SQLite only supports one writer at a time.
|
||||
db.SetMaxOpenConns(1)
|
||||
logger.Info(fmt.Sprintf("Database: SQLite opened (%s)", dbPath))
|
||||
} else {
|
||||
connectString := fmt.Sprintf(
|
||||
"host='%s' port='%d' user='%s' password='%s' dbname='%s' sslmode=disable",
|
||||
config.Database.Host,
|
||||
config.Database.Port,
|
||||
config.Database.User,
|
||||
config.Database.Password,
|
||||
config.Database.Database,
|
||||
)
|
||||
db, err = sqlx.Open("postgres", connectString)
|
||||
if err != nil {
|
||||
preventClose(config, fmt.Sprintf("Database: Failed to open, %s", err.Error()))
|
||||
}
|
||||
// Configure connection pool to avoid exhausting PostgreSQL under load.
|
||||
db.SetMaxOpenConns(50)
|
||||
db.SetMaxIdleConns(10)
|
||||
db.SetConnMaxLifetime(5 * time.Minute)
|
||||
db.SetConnMaxIdleTime(2 * time.Minute)
|
||||
// Create the postgres DB pool.
|
||||
connectString := fmt.Sprintf(
|
||||
"host='%s' port='%d' user='%s' password='%s' dbname='%s' sslmode=disable",
|
||||
config.Database.Host,
|
||||
config.Database.Port,
|
||||
config.Database.User,
|
||||
config.Database.Password,
|
||||
config.Database.Database,
|
||||
)
|
||||
|
||||
db, err := sqlx.Open("postgres", connectString)
|
||||
if err != nil {
|
||||
preventClose(config, fmt.Sprintf("Database: Failed to open, %s", err.Error()))
|
||||
}
|
||||
|
||||
// Test the DB connection.
|
||||
@@ -177,6 +157,12 @@ func main() {
|
||||
preventClose(config, fmt.Sprintf("Database: Failed to ping, %s", err.Error()))
|
||||
}
|
||||
|
||||
// Configure connection pool to avoid exhausting PostgreSQL under load.
|
||||
db.SetMaxOpenConns(50)
|
||||
db.SetMaxIdleConns(10)
|
||||
db.SetConnMaxLifetime(5 * time.Minute)
|
||||
db.SetConnMaxIdleTime(2 * time.Minute)
|
||||
|
||||
logger.Info("Database: Started successfully")
|
||||
|
||||
// Run database migrations
|
||||
|
||||
Reference in New Issue
Block a user