mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-11-16 23:04:24 +08:00
fix(sqlite): enable WAL and export consistent snapshots
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
// Copyright 2026 Arctel.net
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func TestEnableSQLiteWAL(t *testing.T) {
|
||||
for _, tc := range []struct{ name, path, mode string }{
|
||||
{"file", filepath.Join(t.TempDir(), "database.db"), "wal"},
|
||||
{"memory", ":memory:", "memory"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
database, err := gorm.Open(sqlite.Open(tc.path), &gorm.Config{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sqlDB, err := database.DB()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
if err := sqlDB.Close(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
if err := enableSQLiteWAL(database); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var mode string
|
||||
if err := database.Raw("PRAGMA journal_mode").Scan(&mode).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if mode != tc.mode {
|
||||
t.Fatalf("journal mode = %q, want %q", mode, tc.mode)
|
||||
}
|
||||
if err := enableSQLiteWAL(database); err != nil {
|
||||
t.Fatalf("enable WAL again: %v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user