wallet/sql: add database migration foundation - #1288
Open
Roasbeef wants to merge 1 commit into
Open
Conversation
This was referenced Jul 11, 2026
In this commit, we add bounded SQLite and PostgreSQL connection pools and an embedded migration runner that can move the schema from empty to head, back to empty, then forward again. We use the released lnd/sqldb v1.0.13 module for shared SQLite defaults and make its transaction, error, and query utilities available to the later store adapter. The wallet schema and rollback-capable migration runner stay local because the concrete lnd stores own lnd-specific schema and migration ordering. Extracted-from: de762f0 Extracted-from: 2477f80 Extracted-from: 12bedf6 Extracted-from: 9bf5e56 Extracted-from: aa1725a8755db62a8746e46ee8894ab5df3d828a Extracted-from: d7a5127cc08edb68455f1e7ece45564df3fee487 Extracted-from: 7074419bfe3f7dcd393e302d6201177d3e35df49 Extracted-from: 2be43f4108cc143abb83dd8e35f8e5d4d0667fa3 Co-authored-by: Viktor Torstensson <viktor.t.git@gmail.com> Co-authored-by: yyforyongyu <yong2452@gmail.com>
Roasbeef
force-pushed
the
sql-port-stage1-migrations
branch
from
July 11, 2026 01:16
4693da9 to
061430e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In this PR, we add the database connection and migration foundation for the port-first SQL stack.
This PR is stacked on #1287, which adds the build and block-schema foundation.
The SQLite and PostgreSQL pools use bounded connection settings and embedded migrations that can move from empty to head, back to empty, then forward again. PostgreSQL accepts both URL and keyword/value DSNs, enforces TLS without rewriting either form, and runs migrations through a short-lived owned pool so repeated migration calls do not consume the wallet pool. We use the released
github.com/lightningnetwork/lnd/sqldbmodule atv1.0.13for the shared SQL utility layer and SQLite defaults. btcwallet retains its own schema and rollback-capable migration runner because the concrete lnd stores own lnd-specific schema and global migration ordering.No wallet method is routed through SQL in this PR. This only establishes the internal database boundary used by the following schema PRs.
Verification:
go vet ./wallet/internal/sql/...make sqlc-check