Skip to content

db: introduce sqldbv2 scaffolding#235

Merged
bitromortac merged 2 commits into
lightninglabs:faraday-forwarding-abilityfrom
bitromortac:2603-fwd-prep-6
Mar 31, 2026
Merged

db: introduce sqldbv2 scaffolding#235
bitromortac merged 2 commits into
lightninglabs:faraday-forwarding-abilityfrom
bitromortac:2603-fwd-prep-6

Conversation

@bitromortac
Copy link
Copy Markdown
Contributor

Based on #234.

This PR introduces a SQL database to Faraday, which will later be used to track channel state changes.

Uses the exact sqldbv2 version of https://github.com/lightninglabs/lightning-terminal/tree/sql-migration-base and the custom migration library. The scaffolding was copied from this (already reviewed) branch, which should make it easy to compare against.

Corresponding lnd PR: lightningnetwork/lnd#10175

@bitromortac bitromortac requested a review from ViktorT-11 March 24, 2026 14:21
@gemini-code-assist
Copy link
Copy Markdown

Warning

Gemini encountered an error creating the summary. You can try again by commenting /gemini summary.

@bitromortac
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new database layer for Faraday, supporting both SQLite and PostgreSQL. Key changes include the integration of sqlc for generating Go models from SQL schemas and golang-migrate for database migrations. The main Faraday daemon has been significantly refactored to encapsulate RPC server setup, macaroon service management, and lnd client connections, leading to a simplified frdrpcserver package. Supporting changes include new Makefile targets, a sqlc.yaml configuration, and updated dependencies. Review comments primarily address incorrect usage of btclog.Logger methods (Infof, Errorf, Error with format strings) which should be corrected to Info or Error without format strings. Further feedback suggests improving code clarity and maintainability by making DefaultPostgresFixtureLifetime a constant, updating an outdated comment regarding the Postgres version, adding comments for temporary go.mod replace directives, and exploring automation for LatestMigrationVersion to reduce manual errors.

Comment thread faraday.go
Comment thread faraday.go
Comment thread faraday.go
Comment thread db/postgres_fixture.go Outdated
Comment thread faraday.go
Comment thread faraday.go
Comment thread db/migrations.go Outdated
Comment on lines +8 to +9
// NOTE: This MUST be updated when a new migration is added.
LatestMigrationVersion = 1
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The comment NOTE: This MUST be updated when a new migration is added. indicates a manual step that is prone to human error. Consider implementing a mechanism to automatically derive or validate the LatestMigrationVersion during the build or test process to prevent inconsistencies.

Copy link
Copy Markdown
Contributor Author

@bitromortac bitromortac Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add a test in a later PR that checks this.

Comment thread db/postgres.go Outdated
Comment thread db/postgres_fixture.go Outdated
Comment thread go.mod Outdated
@bitromortac
Copy link
Copy Markdown
Contributor Author

Updated to latest sqldbv2 in lnd side branch.

Copy link
Copy Markdown
Contributor

@ViktorT-11 ViktorT-11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this will definitely be useful. Leaving a few comments below 😃

Comment thread Makefile
@$(call print, "Generating sql models and queries in Go")
./scripts/gen_sqlc_docker.sh

sqlc-check: sqlc
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add this check to the CI workflow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I'll add that when we have the migrations since it would fail at the moment: sed: can't read db/sqlc/migrations/*.up.sql: No such file or directory

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense :)

Comment thread make/testing_flags.mk
Comment thread make/testing_flags.mk
Comment thread db/sqlerrors.go Outdated
Comment thread db/postgres.go Outdated
Comment thread db/sqlc/db_custom.go Outdated
@bitromortac
Copy link
Copy Markdown
Contributor Author

Thanks for the great review @ViktorT-11, I could remove a lot of code 🎉

Copy link
Copy Markdown
Contributor

@ViktorT-11 ViktorT-11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, LGTM 🔥!

@bitromortac bitromortac merged commit 69a4a32 into lightninglabs:faraday-forwarding-ability Mar 31, 2026
7 checks passed
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.

3 participants