mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-09-01 16:07:17 +00:00
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:
@@ -886,7 +886,7 @@ func InitDB(dbPath string) error {
|
|||||||
if err = os.MkdirAll(dir, 0755); err != nil {
|
if err = os.MkdirAll(dir, 0755); err != nil {
|
||||||
return err
|
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)
|
db, err = gorm.Open(sqlite.Open(dsn), c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -895,13 +895,13 @@ func InitDB(dbPath string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := sqlDB.Exec("PRAGMA journal_mode=WAL"); err != nil {
|
if _, err := sqlDB.Exec("PRAGMA journal_mode=DELETE"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := sqlDB.Exec("PRAGMA busy_timeout=10000"); err != nil {
|
if _, err := sqlDB.Exec("PRAGMA busy_timeout=10000"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := sqlDB.Exec("PRAGMA synchronous=NORMAL"); err != nil {
|
if _, err := sqlDB.Exec("PRAGMA synchronous=FULL"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user