mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-01 21:02:15 +03:00
* fix(database): snapshot SQLite backups online Use SQLite's online backup API for downloadable backups and SQLite migration exports instead of checkpointing then reading the live database file. The regression test validates a backup made while writes continue. * style(database): group SQLite driver imports * fix(database): bound online backup retries Use a single backup step and a bounded connection-acquisition/retry context. Tighten temporary-file cleanup and regression assertions while removing the unused checkpoint helper. * test(database): cover existing backup destinations * fix(database): harden SQLite snapshot lifecycle Sweep interrupted snapshot directories at SQLite startup, keep rollback-journal backups incremental, and make caller-owned cleanup explicit. Reuse one scheduled Telegram snapshot across administrators and make the direct SQLite driver dependency explicit. --------- Co-authored-by: PathGao <gaoyanbo@gaoyanbodeMacBook-Air.local>
42 lines
974 B
Go
42 lines
974 B
Go
package database
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func journalModeOf(t *testing.T) string {
|
|
t.Helper()
|
|
var mode string
|
|
if err := db.Raw("PRAGMA journal_mode;").Scan(&mode).Error; err != nil {
|
|
t.Fatalf("read journal_mode: %v", err)
|
|
}
|
|
return mode
|
|
}
|
|
|
|
func TestSqliteJournalModeDefaultsToWal(t *testing.T) {
|
|
t.Setenv("XUI_DB_JOURNAL_MODE", "")
|
|
dbDir := t.TempDir()
|
|
if err := InitDB(filepath.Join(dbDir, "x-ui.db")); err != nil {
|
|
t.Fatalf("InitDB: %v", err)
|
|
}
|
|
t.Cleanup(func() { _ = CloseDB() })
|
|
|
|
if got := journalModeOf(t); got != "wal" {
|
|
t.Fatalf("journal_mode = %q, want wal", got)
|
|
}
|
|
}
|
|
|
|
func TestSqliteJournalModeEnvOverrideDelete(t *testing.T) {
|
|
t.Setenv("XUI_DB_JOURNAL_MODE", "delete")
|
|
dbDir := t.TempDir()
|
|
if err := InitDB(filepath.Join(dbDir, "x-ui.db")); err != nil {
|
|
t.Fatalf("InitDB: %v", err)
|
|
}
|
|
t.Cleanup(func() { _ = CloseDB() })
|
|
|
|
if got := journalModeOf(t); got != "delete" {
|
|
t.Fatalf("journal_mode = %q, want delete", got)
|
|
}
|
|
}
|