multi: confirm kvdb migration at startup

Prompt before automatically migrating legacy kvdb state to SQL when
litd starts with a SQL backend and active bbolt data is still present.

Detect prior migrations by checking for the SQL tombstone marker so
already-migrated stores can start without prompting. Add unit coverage
for the prompt flow and wire stdin through the itest harness so the
migration restart path can acknowledge the prompt automatically.
This commit is contained in:
Viktor Torstensson 2026-05-22 14:12:27 +02:00
parent f5046d1f4e
commit 9016bbb3d2
No known key found for this signature in database
GPG key ID: 961CC8259AE675D4
9 changed files with 449 additions and 0 deletions

View file

@ -85,6 +85,31 @@ func CheckKVDBDeprecated(path string, bucketKey []byte,
return nil
}
// HasActiveKVDB reports whether the legacy bbolt database at the given path
// exists and has not yet been tombstoned by a SQL migration in the specified
// top-level bucket. A missing file or a tombstoned database is reported as
// inactive, so callers can use this to detect kvdb state that is still pending
// migration to SQL.
func HasActiveKVDB(path string, bucketKey []byte,
timeout time.Duration) (bool, error) {
if _, err := os.Stat(path); os.IsNotExist(err) {
return false, nil
}
err := CheckKVDBDeprecated(path, bucketKey, timeout)
switch {
case errors.Is(err, ErrKVDBDeprecated):
return false, nil
case err != nil:
return false, err
default:
return true, nil
}
}
// IsMigrationTombstoneKey returns true if the given key is the kvdb migration
// tombstone marker.
func IsMigrationTombstoneKey(key []byte) bool {