- pluggable per-domain Repository interfaces; PostgreSQL and SQLite impls - SQLite on modernc.org/sqlite (WAL, busy_timeout, foreign_keys, immediate tx) - separate migrations/sqlite and db.MigrateSQLite; store.NewPostgres/NewSQLite - cmd/reconcile compares object storage with the journal (report, then --delete) - storage.Backend.List and photos.Repository.AllStorageKeys - DB_BACKEND/SQLITE_PATH and STORAGE_BACKEND/FS_ROOT selectable; local defaults (sqlite ./galo.db, fs ./data) - Makefile reconcile/reconcile-delete; docs and .env.example updated
46 lines
980 B
Go
46 lines
980 B
Go
package db
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestOpenSQLite(t *testing.T) {
|
|
ctx := context.Background()
|
|
db, err := OpenSQLite(filepath.Join(t.TempDir(), "test.db"))
|
|
if err != nil {
|
|
t.Fatalf("open: %v", err)
|
|
}
|
|
defer db.Close()
|
|
|
|
if err := db.PingContext(ctx); err != nil {
|
|
t.Fatalf("ping: %v", err)
|
|
}
|
|
|
|
var mode string
|
|
if err := db.QueryRowContext(ctx, "PRAGMA journal_mode").Scan(&mode); err != nil {
|
|
t.Fatalf("journal_mode: %v", err)
|
|
}
|
|
if !strings.EqualFold(mode, "wal") {
|
|
t.Fatalf("journal_mode = %q, want wal", mode)
|
|
}
|
|
|
|
var fk int
|
|
if err := db.QueryRowContext(ctx, "PRAGMA foreign_keys").Scan(&fk); err != nil {
|
|
t.Fatalf("foreign_keys: %v", err)
|
|
}
|
|
if fk != 1 {
|
|
t.Fatalf("foreign_keys = %d, want 1", fk)
|
|
}
|
|
|
|
var busy int
|
|
if err := db.QueryRowContext(ctx, "PRAGMA busy_timeout").Scan(&busy); err != nil {
|
|
t.Fatalf("busy_timeout: %v", err)
|
|
}
|
|
if busy != 5000 {
|
|
t.Fatalf("busy_timeout = %d, want 5000", busy)
|
|
}
|
|
}
|