chore(db): use DELETE journal mode so sqlite stays a single file

Switch sqlite from WAL to DELETE journal mode so the database no longer
keeps -shm/-wal sidecar files; only x-ui.db remains at rest. Pair with
synchronous=FULL for crash-safe durability in rollback-journal mode.

The startup PRAGMA journal_mode=DELETE converts existing WAL databases
and removes their leftover sidecar files on first run, so upgrades need
no manual cleanup. busy_timeout and _txlock=immediate are unchanged.
This commit is contained in:
MHSanaei
2026-06-20 01:41:00 +02:00
parent af3f460065
commit e079490144
+3 -3
View File
@@ -886,7 +886,7 @@ func InitDB(dbPath string) error {
if err = os.MkdirAll(dir, 0755); err != nil {
return err
}
dsn := dbPath + "?_journal_mode=WAL&_busy_timeout=10000&_synchronous=NORMAL&_txlock=immediate"
dsn := dbPath + "?_journal_mode=DELETE&_busy_timeout=10000&_synchronous=FULL&_txlock=immediate"
db, err = gorm.Open(sqlite.Open(dsn), c)
if err != nil {
return err
@@ -895,13 +895,13 @@ func InitDB(dbPath string) error {
if err != nil {
return err
}
if _, err := sqlDB.Exec("PRAGMA journal_mode=WAL"); err != nil {
if _, err := sqlDB.Exec("PRAGMA journal_mode=DELETE"); err != nil {
return err
}
if _, err := sqlDB.Exec("PRAGMA busy_timeout=10000"); err != nil {
return err
}
if _, err := sqlDB.Exec("PRAGMA synchronous=NORMAL"); err != nil {
if _, err := sqlDB.Exec("PRAGMA synchronous=FULL"); err != nil {
return err
}
}