Skip to content

migrate-db: skip missing source DBs by default#85

Open
0xfandom wants to merge 1 commit intolightninglabs:mainfrom
0xfandom:feat/77-error-if-no-bbolt-db
Open

migrate-db: skip missing source DBs by default#85
0xfandom wants to merge 1 commit intolightninglabs:mainfrom
0xfandom:feat/77-error-if-no-bbolt-db

Conversation

@0xfandom
Copy link
Copy Markdown

@0xfandom 0xfandom commented May 1, 2026

Summary

lndinit migrate-db currently aborts on the first mandatory prefix with database does not exist when run against a fresh node (no bbolt files yet). For container/k8s init wrappers that always run migrate-db, this means the wrapper has to special-case "no DBs yet" or LND never gets a chance to create the SQLite DB itself.

This PR treats ErrDbDoesNotExist on a mandatory prefix the same way it already treats it on an optional one (log + continue), and gates the previous strict behavior behind a new opt-in flag:

--error-if-no-bbolt-db-exists

Off by default so a fresh-node migration is a successful no-op; on for operators who want a hard failure if their bbolt files vanished unexpectedly.

The second flag suggested in the issue (--tombstone-empty-db-if-no-bbolt-db-exists) is intentionally not part of this PR — its use case is unclear and it can be added cleanly on top later if someone wants it.

Testing

  • New TestMigrateDBNoBboltDBExists covers both default-skip and flag-forces-error paths against an empty data dir.
  • go test -tags="kvdb_etcd kvdb_postgres kvdb_sqlite" ./... clean.
  • golangci-lint run --timeout 10m --build-tags="kvdb_etcd kvdb_postgres kvdb_sqlite" ./... clean (v1.64.8 from tools/go.mod).
  • Manual lndinit migrate-db -h confirms the new flag renders.

Related

Fixes #77

Running migrate-db on a fresh node (no bbolt DBs yet) currently aborts
with an unrecoverable "database does not exist" error on the first
mandatory prefix. LND happily creates the destination SQL DB itself on
first start, so a missing source is not actually a failure — it just
means there is nothing to migrate.

Treat ErrDbDoesNotExist on a mandatory prefix the same as on an
optional one (log and continue), and gate the previous strict behavior
behind a new opt-in flag:

  --error-if-no-bbolt-db-exists

The flag is off by default so the no-op case becomes friendly to
container/k8s init wrappers that always run migrate-db, and on for
operators who want a hard failure when their bbolt files have gone
missing unexpectedly.

Fixes lightninglabs#77
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

migrate-db: gracefully handle the case where no bbolt DB exists

1 participant