This commit is contained in:
2026-03-22 22:04:38 +01:00
parent 75d7464655
commit 97d4a990a8
8 changed files with 149 additions and 92 deletions
+3 -1
View File
@@ -10,11 +10,13 @@ import (
func initDB(cfg *Configuration) *sql.DB {
_ = os.MkdirAll(cfg.DatabasePath, 0755)
db, err := sql.Open("sqlite", fmt.Sprintf("%s/ncore_stats.db", cfg.DatabasePath))
db, err := sql.Open("sqlite", fmt.Sprintf("%s/ncore_stats.db?_pragma=busy_timeout(5000)&_pragma=journal_mode(WAL)", cfg.DatabasePath))
if err != nil {
logrus.Fatalf("DB failed: %v", err)
}
db.SetMaxOpenConns(1)
schemas := []string{
`CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, display_name TEXT UNIQUE, profile_id TEXT);`,
`CREATE TABLE IF NOT EXISTS profile_history (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER, timestamp DATETIME, rank INTEGER, upload TEXT, current_upload TEXT, current_download TEXT, points INTEGER, seeding_count INTEGER, FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE);`,