lightning-terminal/session/kvdb_store_deprecation_test.go
Viktor Torstensson 000d28a4fb
multi: deprecate kvdb stores after SQL migration
Mark the legacy kvdb stores as deprecated once the kvdb -> SQL
migration commits successfully. This prevents normal bbolt startup
from reopening accounts.db, session.db, or rules.db after their data
has already been migrated.

Add explicit deprecation checks to the three kvdb store open paths and
provide migration-only constructors that can still reopen deprecated
files when the SQL database is deleted or downgraded and the migration
must be rerun.

Use store-specific tombstones for the deprecation markers and add
tests that verify deprecated stores are rejected while migration
reruns continue to work.
2026-05-14 11:39:14 +02:00

57 lines
1.4 KiB
Go

package session
import (
"os"
"path/filepath"
"testing"
"github.com/lightninglabs/lightning-terminal/accounts"
"github.com/lightninglabs/lightning-terminal/db/tombstone"
"github.com/lightningnetwork/lnd/clock"
"github.com/stretchr/testify/require"
)
// TestKVDBDeprecation verifies that a deprecated session kvdb file refuses to
// reopen.
func TestKVDBDeprecation(t *testing.T) {
t.Parallel()
dbDir := t.TempDir()
clk := clock.NewDefaultClock()
accountStore, err := accounts.NewBoltStore(
dbDir, accounts.DBFilename, clk,
)
require.NoError(t, err)
defer accountStore.Close()
store, err := NewDB(dbDir, DBFilename, clk, accountStore)
require.NoError(t, err)
require.NoError(t, store.Close())
err = DeprecateKVDB(dbDir)
require.NoError(t, err)
_, err = NewDB(dbDir, DBFilename, clk, accountStore)
require.Error(t, err)
require.ErrorIs(t, err, tombstone.ErrKVDBDeprecated)
store, err = NewDBForMigration(dbDir, DBFilename, clk, accountStore)
require.NoError(t, err)
require.NoError(t, store.Close())
}
// TestDeprecateKVDBMissingFile verifies that deprecating a missing session
// kvdb file is a no-op.
func TestDeprecateKVDBMissingFile(t *testing.T) {
t.Parallel()
dbDir := t.TempDir()
dbPath := filepath.Join(dbDir, DBFilename)
err := DeprecateKVDB(dbDir)
require.NoError(t, err)
_, err = os.Stat(dbPath)
require.ErrorIs(t, err, os.ErrNotExist)
}