Skip to content

Conversation

ziggie1984
Copy link
Collaborator

  • sqldb: add missing invoice index for native sql
  • docs: add release-notes

Copy link

@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.

Summary of Changes

Hello @ziggie1984, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new SQL index on the settled_at column of the invoices table to enhance query performance for settled invoices. It also includes an update to the release notes to document this database improvement.

Highlights

  • Database Performance Improvement: A new SQL index (invoices_settled_at_idx) has been added to the invoices table on the settled_at column. This is intended to significantly speed up queries involving settled invoices.
  • Migration Script Updates: New migration files (000008_invoice_add_settled_index.up.sql and .down.sql) were added to manage the creation and deletion of the new index. Existing migration 000001_invoices.down.sql was also updated to reflect index management changes.
  • Documentation: The docs/release-notes/release-notes-0.20.0.md file has been updated to inform users about the addition of this new SQL index.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@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 adds a missing database index on the settled_at column of the invoices table to improve query performance. This is achieved by adding a new migration file for existing databases and updating the initial down migration. A release note for this change is also included. The changes are logical, but I've found a critical issue in the new down migration file where a typo in the index name would prevent the migration from being rolled back correctly.

@ziggie1984 ziggie1984 force-pushed the add-missing-invoice-settle-index branch 2 times, most recently from 56160c8 to 3ed910b Compare August 13, 2025 13:51
@ziggie1984 ziggie1984 self-assigned this Aug 13, 2025
Copy link
Collaborator

@bhandras bhandras left a comment

Choose a reason for hiding this comment

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

LGTM, thank you! 🎉

Copy link
Collaborator

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

nice! just need to please first squash in the fixup commit

@ziggie1984 ziggie1984 force-pushed the add-missing-invoice-settle-index branch from b48c8d4 to 61c0fec Compare August 13, 2025 20:27
@ziggie1984
Copy link
Collaborator Author

Ohh actually this PR forgot to use this new schema and update the DB, so I put this new schema in the dev migration table so that nothing has to be changed for the graph stuff.

@ziggie1984 ziggie1984 requested a review from ellemouton August 13, 2025 20:29
@ziggie1984
Copy link
Collaborator Author

@gemini-code-assist why did you not notice that I forgot using the new migration file in the migration table ?

Copy link

Hi @ziggie1984,

Thank you for your question. My review is based on the code changes present in the pull request at the time of the review.

Looking at the provided patches, the sqldb/migrations_dev.go file was indeed modified to include the 000008_invoice_add_settled_index migration. This change is visible in the diff for sqldb/migrations_dev.go:

--- a/sqldb/migrations_dev.go
+++ b/sqldb/migrations_dev.go
@@ -17,4 +17,9 @@ var migrationAdditions = []MigrationConfig{
 		// schema. This is optional and can be disabled by the
 		// user if necessary.
 	},
+	{
+		Name:          "000008_invoice_add_settled_index",
+		Version:       10,
+		SchemaVersion: 8,
+	},
 }

Therefore, this particular change was part of the pull request I reviewed. If there was an earlier version of the PR where this was missing, my review would not have been able to comment on that prior state.

@ziggie1984 ziggie1984 requested a review from bhandras August 13, 2025 20:55
@ziggie1984
Copy link
Collaborator Author

Verified on local node with sqlite build flag, migration was applied and index shows up:

Uploading Screenshot 2025-08-14 at 07.25.33.png…

Copy link
Collaborator

@bhandras bhandras left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

@ziggie1984 ziggie1984 force-pushed the add-missing-invoice-settle-index branch 3 times, most recently from beacf8e to 98897fb Compare August 14, 2025 05:57
@ziggie1984 ziggie1984 requested a review from ellemouton August 14, 2025 05:57
Copy link
Collaborator

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

@ziggie1984 -you'll also need to update it here:

// graphSQLMigration is the version number for the graph migration
// that migrates the KV graph to the native SQL schema.
const graphSQLMigration = 9

@ziggie1984 ziggie1984 force-pushed the add-missing-invoice-settle-index branch from 98897fb to 1210a56 Compare August 14, 2025 06:17
@bhandras bhandras self-requested a review August 14, 2025 06:27
@ziggie1984
Copy link
Collaborator Author

I added a schema_update doc, pretty hard to write a test on the current version with all the build tags, so I think this doc will help also the AI to make sure schema updates are done properly. This should be obsolete as soon as sqldb/v2 lands.

@ziggie1984
Copy link
Collaborator Author

@gemini-code-assist can you verifiy based on the schema update document whether this PR is correct

@ziggie1984 ziggie1984 requested a review from ellemouton August 14, 2025 07:30
Copy link

Hi @ziggie1984,

Thank you for adding the sqldb/SCHEMA_UPDATES.md document. I've reviewed the changes in this pull request against the guidelines outlined in this new documentation, and I can confirm that the schema updates implemented here are consistent with the process described in SCHEMA_UPDATES.md.

Specifically:

  • The new SQL migration files (000007_invoice_add_settled_index.up.sql and .down.sql) are correctly added.
  • The corresponding MigrationConfig entries in sqldb/migrations_prod.go and sqldb/migrations_dev.go reflect the correct Name, Version, and SchemaVersion for the new index and the renumbered graph migration.
  • The update to config_test_native_sql.go for the graphSQLMigration constant aligns with the custom migration function guidelines.

This new documentation is a valuable addition and will certainly help ensure future schema updates are done properly.

@ziggie1984 ziggie1984 force-pushed the add-missing-invoice-settle-index branch from 095bffa to 0157099 Compare August 14, 2025 08:40
@ziggie1984 ziggie1984 requested a review from ellemouton August 14, 2025 09:26
Copy link
Collaborator

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

lgtm! one commit message is just outdated now

graphExecutor, opts...,
)
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

commit message is incorrect!

@@ -0,0 +1,224 @@
# SQL Schema Updates in LND
Copy link
Collaborator

Choose a reason for hiding this comment

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

very nice docs 🙏 hopefully much of this complexity will be reduced once we switch to sqldbv2

We put this new schema update into the main line and change the
versions of the schema updates which are currently only available
in dev builds. The schemas need to be chronological therefore we
also need to rename the file numbers.
@ziggie1984 ziggie1984 force-pushed the add-missing-invoice-settle-index branch from 0157099 to 35e9979 Compare August 14, 2025 10:01
Copy link
Collaborator

@bhandras bhandras left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

Really nice doc!

@guggero guggero merged commit 31fc556 into lightningnetwork:master Aug 14, 2025
24 checks passed
@ziggie1984 ziggie1984 deleted the add-missing-invoice-settle-index branch August 14, 2025 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants