lightning-terminal/accounts/store_kvdb_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

50 lines
1.2 KiB
Go

package accounts
import (
"os"
"path/filepath"
"testing"
"github.com/lightninglabs/lightning-terminal/db/tombstone"
"github.com/lightningnetwork/lnd/clock"
"github.com/stretchr/testify/require"
)
// TestKVDBDeprecation verifies that a deprecated accounts kvdb file refuses to
// reopen.
func TestKVDBDeprecation(t *testing.T) {
t.Parallel()
dbDir := t.TempDir()
clk := clock.NewDefaultClock()
store, err := NewBoltStore(dbDir, DBFilename, clk)
require.NoError(t, err)
require.NoError(t, store.Close())
err = DeprecateKVDB(dbDir)
require.NoError(t, err)
_, err = NewBoltStore(dbDir, DBFilename, clk)
require.Error(t, err)
require.ErrorIs(t, err, tombstone.ErrKVDBDeprecated)
store, err = NewBoltStoreForMigration(dbDir, DBFilename, clk)
require.NoError(t, err)
require.NoError(t, store.Close())
}
// TestDeprecateKVDBMissingFile verifies that deprecating a missing accounts
// 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)
}