Skip to content

wallet/sql: add database migration foundation#1288

Open
Roasbeef wants to merge 1 commit into
sql-port-stage1-foundationfrom
sql-port-stage1-migrations
Open

wallet/sql: add database migration foundation#1288
Roasbeef wants to merge 1 commit into
sql-port-stage1-foundationfrom
sql-port-stage1-migrations

Conversation

@Roasbeef

Copy link
Copy Markdown
Member

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/sqldb module at v1.0.13 for 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:

  • SQLite empty-to-head-to-empty-to-head migration test
  • PostgreSQL empty-to-head-to-empty-to-head migration test
  • go vet ./wallet/internal/sql/...
  • make sqlc-check

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
Roasbeef force-pushed the sql-port-stage1-migrations branch from 4693da9 to 061430e Compare July 11, 2026 01:16
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.

2 participants