Skip to content

[sql-43] Add support for sqldb/v2 in litd #1085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

ViktorTigerstrom
Copy link
Contributor

@ViktorTigerstrom ViktorTigerstrom commented Jun 10, 2025

Currently based on #1079

Implements step 1. of "Phase 3" in #917.

This is a draft PR to updates litd to use the new sqldd/v2 package. Note that this with just this PR, litd will not utilize the capabilities of sqldb v2 to run specific post migrations steps (such as migrating the kvdb to SQL). That functionality will be added in upcoming PRs.

Instead, this PR just focuses on adding support for the new sqldb v2 package, and the functionality of the SQL stores are expected to remain the same as prior to this commit.

Note that this is only a draft PR for now, as the sqldb/v2 is not released, and we therefore need to add forked+local dependencies in order to run this. Once we have an official release of the sqldb/v2 package, I'll update this PR to use that dependency.

Even though the code is complete in this PR, I will splits up the commits more, and this PR is currently not ready for review due to that and due to the above, and is currently only made for reference.

@ellemouton
Copy link
Member

@ViktorTigerstrom - maybe change the base branch so we only see the relevant commits here?

We add a helper function to the functions that creates the test SQL
stores, in order to ensure that the store is properly closed when the
test is cleaned up.
In the upcoming migration of the firewall database to SQL, the helper
functions that creates the test databases of different types, need to
return a unified interface in order to not have to control the
migration tests file by build tags. Therefore, we export the unified
interface FirewallDBs, so that it can be returned public test DB
creation functions
In the upcoming migration of the firewall database to SQL, the helper
functions that creates the test databases of different types, need to
return a unified interface in order to not have to control the
migration tests file by build tags. Therefore, we update the
`NewTestDB` functions to return the `FirewallDBs` interface instead of
the specific store implementation type.
During the upcoming upcoming migration of the firewall database to SQL,
we need to be able to check all kvstores records in the SQL database,
to validate that the migration is successful in tests.

This commits adds a query to list all kvstores records, which enables
that functionality.
Rename the session_id to group_id in kvstores table in the SQL store, to
better represent how the field is actually used.

Note that this is a breaking change, and would normally require a new
migration. But as the SQL store is not used in production, and only
enabled under the dev build flag, we can rename it without a new
migration, as there's no users of the SQL store in production.
During the migration of the kvstores to SQL, we'll iterate over the
buckets in the bbolt database, which holds all kvstores records.

In order to understand why the migration iterates over the buckets in
the specific order, we need to clarify the bbolt kvstores illustration
docs, so that it correctly reflects how the records are actually stored
in the bbolt database.
This commit introduces the migration logic for transitioning the
kvstores store from kvdb to SQL.

Note that as of this commit, the migration is not yet triggered by any
production code, i.e. only tests execute the migration logic.
This commit updates litd to use the new sqldb v2 package. Note that this
with just this commit, litd will not utilize the capabilities of sqldb
v2 to run specific post migrations steps (such as migrating the kvdb to
SQL). That functionality will be added in later commits.

Instead, this commit just focuses on adding support for the new
sqldb v2 package, and the functionality of the SQL stores are expected
to remain the same as prior to this commit.
rename `sqlStore` to `store` in the firewalldb sql migration test file,
to make the name shorted. This is done in preparation for future commits
which will lengthen the lines where `sqlStore` is used, which otherwise
would make the lines exceed the 80 character limit.
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