feat: add SQLite support, setup wizard enhancements, and live dashboard

Add zero-dependency SQLite mode so users can run Erupe without
PostgreSQL. A transparent db.DB wrapper auto-translates PostgreSQL
SQL ($N placeholders, now(), ::casts, ILIKE, public. prefix,
TRUNCATE) for SQLite at runtime — all 28 repo files use the wrapper
with no per-query changes needed.

Setup wizard gains two new steps: quest file detection with download
link, and gameplay presets (solo/small/community/rebalanced). The API
server gets a /dashboard endpoint with auto-refreshing stats.

CI release workflow now builds and pushes Docker images to GHCR
alongside binary artifacts on tag push.

Key changes:
- common/db: DB/Tx wrapper with 6 SQL translation rules
- server/migrations/sqlite: full SQLite schema (0001-0005)
- config: Database.Driver field ("postgres" or "sqlite")
- main.go: SQLite connection with WAL mode, single writer
- server/setup: quest check + preset selection steps
- server/api: /dashboard with live stats
- .github/workflows: Docker in release, deduplicate docker.yml
This commit is contained in:
Houmgaor
2026-03-05 18:00:30 +01:00
parent 03adb21e99
commit ecfe58ffb4
86 changed files with 2326 additions and 356 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq"
"go.uber.org/zap"
_ "modernc.org/sqlite"
)
func testDB(t *testing.T) *sqlx.DB {
@@ -194,7 +195,7 @@ func TestParseVersion(t *testing.T) {
}
func TestReadMigrations(t *testing.T) {
migrations, err := readMigrations()
migrations, err := readMigrations(false)
if err != nil {
t.Fatalf("readMigrations failed: %v", err)
}
@@ -210,7 +211,7 @@ func TestReadMigrations(t *testing.T) {
}
func TestReadMigrations_Sorted(t *testing.T) {
migrations, err := readMigrations()
migrations, err := readMigrations(false)
if err != nil {
t.Fatalf("readMigrations failed: %v", err)
}
@@ -223,7 +224,7 @@ func TestReadMigrations_Sorted(t *testing.T) {
}
func TestReadMigrations_AllHaveSQL(t *testing.T) {
migrations, err := readMigrations()
migrations, err := readMigrations(false)
if err != nil {
t.Fatalf("readMigrations failed: %v", err)
}
@@ -235,7 +236,7 @@ func TestReadMigrations_AllHaveSQL(t *testing.T) {
}
func TestReadMigrations_BaselineIsLargest(t *testing.T) {
migrations, err := readMigrations()
migrations, err := readMigrations(false)
if err != nil {
t.Fatalf("readMigrations failed: %v", err)
}
@@ -252,6 +253,61 @@ func TestReadMigrations_BaselineIsLargest(t *testing.T) {
}
}
func TestReadMigrations_SQLite(t *testing.T) {
migrations, err := readMigrations(true)
if err != nil {
t.Fatalf("readMigrations(sqlite) failed: %v", err)
}
if len(migrations) != 5 {
t.Fatalf("expected 5 SQLite migrations, got %d", len(migrations))
}
if migrations[0].filename != "0001_init.sql" {
t.Errorf("first SQLite migration = %q, want 0001_init.sql", migrations[0].filename)
}
for _, m := range migrations {
if m.sql == "" {
t.Errorf("SQLite migration %s has empty SQL", m.filename)
}
}
}
func TestSQLiteMigrateInMemory(t *testing.T) {
db, err := sqlx.Open("sqlite", ":memory:?_pragma=foreign_keys(1)")
if err != nil {
t.Fatalf("Failed to open in-memory SQLite: %v", err)
}
defer func() { _ = db.Close() }()
logger, _ := zap.NewDevelopment()
applied, err := Migrate(db, logger)
if err != nil {
t.Fatalf("Migrate to SQLite failed: %v", err)
}
if applied != 5 {
t.Errorf("expected 5 migrations applied, got %d", applied)
}
ver, err := Version(db)
if err != nil {
t.Fatalf("Version failed: %v", err)
}
if ver != 5 {
t.Errorf("expected version 5, got %d", ver)
}
// Verify a few key tables exist
for _, table := range []string{"users", "characters", "guilds", "guild_characters", "sign_sessions"} {
var count int
err := db.QueryRow("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name=?", table).Scan(&count)
if err != nil {
t.Errorf("Failed to check table %s: %v", table, err)
}
if count != 1 {
t.Errorf("Table %s not found in SQLite schema", table)
}
}
}
func TestParseVersion_Comprehensive(t *testing.T) {
tests := []struct {
filename string