Skip to content

[sql-59] Add kv store kvdb->SQL migration itest#1217

Open
ViktorT-11 wants to merge 1 commit intolightninglabs:migration-itest-sessionsfrom
ViktorT-11:2025-01-kvstores-migration-itest
Open

[sql-59] Add kv store kvdb->SQL migration itest#1217
ViktorT-11 wants to merge 1 commit intolightninglabs:migration-itest-sessionsfrom
ViktorT-11:2025-01-kvstores-migration-itest

Conversation

@ViktorT-11
Copy link
Contributor

Based on #1211

Implements part of step 6. of "Phase 3" in #917.

This PR implements itest coverage for the migration of kv store values.

Implement itest coverage for migrating kv entries data from kvdb to sql.
The itest coverage mimics the unit tests for kv stores in
firewalldb/sql_migration_test.go, except for the randomized migration
tests.

This coverage ensures that the full kvdb->SQL migration flow for litd
works as expected for the kv entries.
@ViktorT-11 ViktorT-11 changed the base branch from master to migration-itest-sessions January 29, 2026 18:06
@ViktorT-11 ViktorT-11 added the no-changelog This PR is does not require a release notes entry label Jan 29, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @ViktorT-11, 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 comprehensive integration test for the migration of existing key-value store data to a SQL database. This is a critical step in modernizing the application's data persistence layer. The changes also encompass an update to the Go programming language version and substantial architectural improvements to how SQL database interactions are managed, utilizing a new sqldb/v2 module and a specialized sqlcmig6 package for migration-related queries.

Highlights

  • KV Store to SQL Migration iTest: An integration test has been added to validate the migration of key-value store data (accounts, sessions, and firewall rules) to a SQL database backend. This test ensures data integrity and correctness during the transition.
  • Go Version Update: The project's Go version has been updated from 1.24.9 to 1.24.11 across all relevant modules, Dockerfiles, and build configurations.
  • SQL Database Abstraction and Refactoring: Significant refactoring has been performed to improve SQL database interactions. This includes leveraging the new lnd/sqldb/v2 module for generic database operations and introducing a dedicated db/sqlcmig6 package for migration-specific SQL queries, ensuring a cleaner separation of concerns.
  • Programmatic Migration Callback: The KV store to SQL migration logic is now integrated as a programmatic migration callback within the db/migrationstreams package. This callback is automatically executed during database schema upgrades in development environments.
  • Linter Configuration for Generated Code: The .golangci.yml configuration has been updated to exclude the newly introduced db/sqlcmig6 package from line length checks, accommodating the nature of generated code.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/main.yml
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 PR adds integration test coverage for the migration of firewall key-value store data from bbolt to SQL. The changes are well-contained within the itest/litd_migration_test.go file and follow the existing structure for migration tests. The test cases are comprehensive, covering various scenarios for global, session-specific, and feature-specific KV entries. I have a couple of suggestions to improve code clarity and reduce duplication.

Comment on lines +1587 to +1596
switch {
case entry.groupAlias == nil && !entry.perm:
store = tx.GlobalTemp()
case entry.groupAlias == nil && entry.perm:
store = tx.Global()
case entry.groupAlias != nil && !entry.perm:
store = tx.LocalTemp()
default:
store = tx.Local()
}

Choose a reason for hiding this comment

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

medium

This switch statement for selecting the correct KVStore is duplicated in the insertFirewallKVEntry function (lines 1354-1363). To improve maintainability and reduce code duplication, consider extracting this logic into a shared helper function. For example:

func getFirewallKVStore(tx firewalldb.KVStoreTx, entry *firewallKVEntryExpectation) firewalldb.KVStore {
	switch {
	case entry.groupAlias == nil && !entry.perm:
		return tx.GlobalTemp()
	case entry.groupAlias == nil && entry.perm:
		return tx.Global()
	case entry.groupAlias != nil && !entry.perm:
		return tx.LocalTemp()
	default: // entry.groupAlias != nil && entry.perm
		return tx.Local()
	}
}

This helper could then be called from both insertFirewallKVEntry and assertFirewallKVEntryBolt.

@lightninglabs-deploy
Copy link

@ViktorT-11, remember to re-request review from reviewers when ready

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

Labels

no-changelog This PR is does not require a release notes entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants