Skip to content

[sql-27]: db/sqlc: kvstores schemas & queries #1028

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

Merged
merged 1 commit into from
Apr 10, 2025

Conversation

ellemouton
Copy link
Member

@ellemouton ellemouton commented Apr 7, 2025

In this commit, we define the schemas and queries that are needed to implement the firewalldb's KVStores in SQL.
NOTE: this PR does not make use of the new queries at all. See this draft PR for how these queries will be used.

See the schema here
LiT KVStore Schema

This part of the #917 project. The PR after this one will use the new queries to implement a SQL version of the RulesDB interface.

@ellemouton ellemouton added database Postgres and sql related issues no-changelog This PR is does not require a release notes entry sql-ize labels Apr 7, 2025
@ellemouton ellemouton self-assigned this Apr 7, 2025
Copy link
Contributor

@bitromortac bitromortac left a comment

Choose a reason for hiding this comment

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

Nice 🔥, I have a few suggestions. Cool tool for the visualization, is there a way to import the schema?

Comment on lines 23 to 25
-- name: InsertKVStoreRecord :exec
INSERT INTO kvstores (perm, rule_id, session_id, feature_id, key, value)
VALUES ($1, $2, $3, $4, $5, $6);
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this would be more work on the interface side, but would it be worth it to instead have an upsert query for this and the update ones?

Copy link
Member Author

Choose a reason for hiding this comment

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

can you explain a bit more? what is the benefit here?

Copy link
Member Author

Choose a reason for hiding this comment

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

(happy to update, just want to understand the reason)

Copy link
Member Author

Choose a reason for hiding this comment

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

(maybe also check the referencing PR to see how these queries are being used)

Copy link
Contributor

Choose a reason for hiding this comment

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

the motivation was just to unify the Get and Update methods, to have less code, but it would also interact with the uniqueness constraint via ON CONFLICT

-- name: UpsertKVStoreRecord :exec
INSERT INTO kvstores (perm, rule_id, session_id, feature_id, key, value)
VALUES ($1, $2, $3, $4, $5, $6)
ON CONFLICT(key, rule_id, perm, session_id, feature_id)
DO UPDATE SET value = excluded.value;

or is it better to separate the write (update/delete) methods for the different kvstore types?

Copy link
Member Author

Choose a reason for hiding this comment

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

oh i see! great idea 🙏

Copy link
Member Author

Choose a reason for hiding this comment

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

this turned out not to work - the conflict doesnt seem to get caught properly for null values. reverting

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, thank you for trying!

@ellemouton ellemouton changed the title db/sqlc: kvstores schemas & queries [sql-27]: db/sqlc: kvstores schemas & queries Apr 7, 2025
@ellemouton ellemouton requested review from bitromortac and removed request for ViktorTigerstrom and bitromortac April 9, 2025 07:58
@ellemouton ellemouton force-pushed the sql27 branch 4 times, most recently from 45bf999 to 1f3592d Compare April 9, 2025 14:14
Copy link
Contributor

@bitromortac bitromortac left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

Copy link
Contributor

@ViktorTigerstrom ViktorTigerstrom left a comment

Choose a reason for hiding this comment

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

Looks good, awesome work 🔥! Only leaving a comment in regards to the un-namned unique index we've discussed before. Think that should be addressed before we merge this :)?

id INTEGER PRIMARY KEY,

-- The unique name of the rule.
name TEXT NOT NULL UNIQUE
Copy link
Contributor

Choose a reason for hiding this comment

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

This is creating an un-namned unique index, which may the same issues we've discussed previously in regards to updates of it :).

Copy link
Member Author

Choose a reason for hiding this comment

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

cool - good idea. i originally thought that was mainly for composite indexes - but you're right, makes sense here too

In this commit, we define the schemas and queries that are needed to
implement the firewalldb's KVStores in SQL.
Copy link
Contributor

@ViktorTigerstrom ViktorTigerstrom 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 ⚡🔥!

@ellemouton ellemouton merged commit 28483b5 into lightninglabs:master Apr 10, 2025
20 of 21 checks passed
@ellemouton ellemouton deleted the sql27 branch April 10, 2025 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database Postgres and sql related issues no-changelog This PR is does not require a release notes entry sql-ize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants