mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
multi: rename sql kvstores session_id to group_id
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.
This commit is contained in:
parent
f84e24491b
commit
75f6137d80
6 changed files with 135 additions and 135 deletions
|
|
@ -25,7 +25,7 @@ DELETE FROM kvstores
|
|||
WHERE entry_key = $1
|
||||
AND rule_id = $2
|
||||
AND perm = $3
|
||||
AND session_id = $4
|
||||
AND group_id = $4
|
||||
AND feature_id = $5
|
||||
`
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ type DeleteFeatureKVStoreRecordParams struct {
|
|||
Key string
|
||||
RuleID int64
|
||||
Perm bool
|
||||
SessionID sql.NullInt64
|
||||
GroupID sql.NullInt64
|
||||
FeatureID sql.NullInt64
|
||||
}
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ func (q *Queries) DeleteFeatureKVStoreRecord(ctx context.Context, arg DeleteFeat
|
|||
arg.Key,
|
||||
arg.RuleID,
|
||||
arg.Perm,
|
||||
arg.SessionID,
|
||||
arg.GroupID,
|
||||
arg.FeatureID,
|
||||
)
|
||||
return err
|
||||
|
|
@ -53,7 +53,7 @@ DELETE FROM kvstores
|
|||
WHERE entry_key = $1
|
||||
AND rule_id = $2
|
||||
AND perm = $3
|
||||
AND session_id IS NULL
|
||||
AND group_id IS NULL
|
||||
AND feature_id IS NULL
|
||||
`
|
||||
|
||||
|
|
@ -68,28 +68,28 @@ func (q *Queries) DeleteGlobalKVStoreRecord(ctx context.Context, arg DeleteGloba
|
|||
return err
|
||||
}
|
||||
|
||||
const deleteSessionKVStoreRecord = `-- name: DeleteSessionKVStoreRecord :exec
|
||||
const deleteGroupKVStoreRecord = `-- name: DeleteGroupKVStoreRecord :exec
|
||||
DELETE FROM kvstores
|
||||
WHERE entry_key = $1
|
||||
AND rule_id = $2
|
||||
AND perm = $3
|
||||
AND session_id = $4
|
||||
AND group_id = $4
|
||||
AND feature_id IS NULL
|
||||
`
|
||||
|
||||
type DeleteSessionKVStoreRecordParams struct {
|
||||
Key string
|
||||
RuleID int64
|
||||
Perm bool
|
||||
SessionID sql.NullInt64
|
||||
type DeleteGroupKVStoreRecordParams struct {
|
||||
Key string
|
||||
RuleID int64
|
||||
Perm bool
|
||||
GroupID sql.NullInt64
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteSessionKVStoreRecord(ctx context.Context, arg DeleteSessionKVStoreRecordParams) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteSessionKVStoreRecord,
|
||||
func (q *Queries) DeleteGroupKVStoreRecord(ctx context.Context, arg DeleteGroupKVStoreRecordParams) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteGroupKVStoreRecord,
|
||||
arg.Key,
|
||||
arg.RuleID,
|
||||
arg.Perm,
|
||||
arg.SessionID,
|
||||
arg.GroupID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
|
@ -113,7 +113,7 @@ FROM kvstores
|
|||
WHERE entry_key = $1
|
||||
AND rule_id = $2
|
||||
AND perm = $3
|
||||
AND session_id = $4
|
||||
AND group_id = $4
|
||||
AND feature_id = $5
|
||||
`
|
||||
|
||||
|
|
@ -121,7 +121,7 @@ type GetFeatureKVStoreRecordParams struct {
|
|||
Key string
|
||||
RuleID int64
|
||||
Perm bool
|
||||
SessionID sql.NullInt64
|
||||
GroupID sql.NullInt64
|
||||
FeatureID sql.NullInt64
|
||||
}
|
||||
|
||||
|
|
@ -130,7 +130,7 @@ func (q *Queries) GetFeatureKVStoreRecord(ctx context.Context, arg GetFeatureKVS
|
|||
arg.Key,
|
||||
arg.RuleID,
|
||||
arg.Perm,
|
||||
arg.SessionID,
|
||||
arg.GroupID,
|
||||
arg.FeatureID,
|
||||
)
|
||||
var value []byte
|
||||
|
|
@ -144,7 +144,7 @@ FROM kvstores
|
|||
WHERE entry_key = $1
|
||||
AND rule_id = $2
|
||||
AND perm = $3
|
||||
AND session_id IS NULL
|
||||
AND group_id IS NULL
|
||||
AND feature_id IS NULL
|
||||
`
|
||||
|
||||
|
|
@ -161,6 +161,35 @@ func (q *Queries) GetGlobalKVStoreRecord(ctx context.Context, arg GetGlobalKVSto
|
|||
return value, err
|
||||
}
|
||||
|
||||
const getGroupKVStoreRecord = `-- name: GetGroupKVStoreRecord :one
|
||||
SELECT value
|
||||
FROM kvstores
|
||||
WHERE entry_key = $1
|
||||
AND rule_id = $2
|
||||
AND perm = $3
|
||||
AND group_id = $4
|
||||
AND feature_id IS NULL
|
||||
`
|
||||
|
||||
type GetGroupKVStoreRecordParams struct {
|
||||
Key string
|
||||
RuleID int64
|
||||
Perm bool
|
||||
GroupID sql.NullInt64
|
||||
}
|
||||
|
||||
func (q *Queries) GetGroupKVStoreRecord(ctx context.Context, arg GetGroupKVStoreRecordParams) ([]byte, error) {
|
||||
row := q.db.QueryRowContext(ctx, getGroupKVStoreRecord,
|
||||
arg.Key,
|
||||
arg.RuleID,
|
||||
arg.Perm,
|
||||
arg.GroupID,
|
||||
)
|
||||
var value []byte
|
||||
err := row.Scan(&value)
|
||||
return value, err
|
||||
}
|
||||
|
||||
const getOrInsertFeatureID = `-- name: GetOrInsertFeatureID :one
|
||||
INSERT INTO features (name)
|
||||
VALUES ($1)
|
||||
|
|
@ -202,44 +231,15 @@ func (q *Queries) GetRuleID(ctx context.Context, name string) (int64, error) {
|
|||
return id, err
|
||||
}
|
||||
|
||||
const getSessionKVStoreRecord = `-- name: GetSessionKVStoreRecord :one
|
||||
SELECT value
|
||||
FROM kvstores
|
||||
WHERE entry_key = $1
|
||||
AND rule_id = $2
|
||||
AND perm = $3
|
||||
AND session_id = $4
|
||||
AND feature_id IS NULL
|
||||
`
|
||||
|
||||
type GetSessionKVStoreRecordParams struct {
|
||||
Key string
|
||||
RuleID int64
|
||||
Perm bool
|
||||
SessionID sql.NullInt64
|
||||
}
|
||||
|
||||
func (q *Queries) GetSessionKVStoreRecord(ctx context.Context, arg GetSessionKVStoreRecordParams) ([]byte, error) {
|
||||
row := q.db.QueryRowContext(ctx, getSessionKVStoreRecord,
|
||||
arg.Key,
|
||||
arg.RuleID,
|
||||
arg.Perm,
|
||||
arg.SessionID,
|
||||
)
|
||||
var value []byte
|
||||
err := row.Scan(&value)
|
||||
return value, err
|
||||
}
|
||||
|
||||
const insertKVStoreRecord = `-- name: InsertKVStoreRecord :exec
|
||||
INSERT INTO kvstores (perm, rule_id, session_id, feature_id, entry_key, value)
|
||||
INSERT INTO kvstores (perm, rule_id, group_id, feature_id, entry_key, value)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
`
|
||||
|
||||
type InsertKVStoreRecordParams struct {
|
||||
Perm bool
|
||||
RuleID int64
|
||||
SessionID sql.NullInt64
|
||||
GroupID sql.NullInt64
|
||||
FeatureID sql.NullInt64
|
||||
EntryKey string
|
||||
Value []byte
|
||||
|
|
@ -249,7 +249,7 @@ func (q *Queries) InsertKVStoreRecord(ctx context.Context, arg InsertKVStoreReco
|
|||
_, err := q.db.ExecContext(ctx, insertKVStoreRecord,
|
||||
arg.Perm,
|
||||
arg.RuleID,
|
||||
arg.SessionID,
|
||||
arg.GroupID,
|
||||
arg.FeatureID,
|
||||
arg.EntryKey,
|
||||
arg.Value,
|
||||
|
|
@ -258,7 +258,7 @@ func (q *Queries) InsertKVStoreRecord(ctx context.Context, arg InsertKVStoreReco
|
|||
}
|
||||
|
||||
const listAllKVStoresRecords = `-- name: ListAllKVStoresRecords :many
|
||||
SELECT id, perm, rule_id, session_id, feature_id, entry_key, value
|
||||
SELECT id, perm, rule_id, group_id, feature_id, entry_key, value
|
||||
FROM kvstores
|
||||
`
|
||||
|
||||
|
|
@ -275,7 +275,7 @@ func (q *Queries) ListAllKVStoresRecords(ctx context.Context) ([]Kvstore, error)
|
|||
&i.ID,
|
||||
&i.Perm,
|
||||
&i.RuleID,
|
||||
&i.SessionID,
|
||||
&i.GroupID,
|
||||
&i.FeatureID,
|
||||
&i.EntryKey,
|
||||
&i.Value,
|
||||
|
|
@ -299,7 +299,7 @@ SET value = $1
|
|||
WHERE entry_key = $2
|
||||
AND rule_id = $3
|
||||
AND perm = $4
|
||||
AND session_id = $5
|
||||
AND group_id = $5
|
||||
AND feature_id = $6
|
||||
`
|
||||
|
||||
|
|
@ -308,7 +308,7 @@ type UpdateFeatureKVStoreRecordParams struct {
|
|||
Key string
|
||||
RuleID int64
|
||||
Perm bool
|
||||
SessionID sql.NullInt64
|
||||
GroupID sql.NullInt64
|
||||
FeatureID sql.NullInt64
|
||||
}
|
||||
|
||||
|
|
@ -318,7 +318,7 @@ func (q *Queries) UpdateFeatureKVStoreRecord(ctx context.Context, arg UpdateFeat
|
|||
arg.Key,
|
||||
arg.RuleID,
|
||||
arg.Perm,
|
||||
arg.SessionID,
|
||||
arg.GroupID,
|
||||
arg.FeatureID,
|
||||
)
|
||||
return err
|
||||
|
|
@ -330,7 +330,7 @@ SET value = $1
|
|||
WHERE entry_key = $2
|
||||
AND rule_id = $3
|
||||
AND perm = $4
|
||||
AND session_id IS NULL
|
||||
AND group_id IS NULL
|
||||
AND feature_id IS NULL
|
||||
`
|
||||
|
||||
|
|
@ -351,31 +351,31 @@ func (q *Queries) UpdateGlobalKVStoreRecord(ctx context.Context, arg UpdateGloba
|
|||
return err
|
||||
}
|
||||
|
||||
const updateSessionKVStoreRecord = `-- name: UpdateSessionKVStoreRecord :exec
|
||||
const updateGroupKVStoreRecord = `-- name: UpdateGroupKVStoreRecord :exec
|
||||
UPDATE kvstores
|
||||
SET value = $1
|
||||
WHERE entry_key = $2
|
||||
AND rule_id = $3
|
||||
AND perm = $4
|
||||
AND session_id = $5
|
||||
AND group_id = $5
|
||||
AND feature_id IS NULL
|
||||
`
|
||||
|
||||
type UpdateSessionKVStoreRecordParams struct {
|
||||
Value []byte
|
||||
Key string
|
||||
RuleID int64
|
||||
Perm bool
|
||||
SessionID sql.NullInt64
|
||||
type UpdateGroupKVStoreRecordParams struct {
|
||||
Value []byte
|
||||
Key string
|
||||
RuleID int64
|
||||
Perm bool
|
||||
GroupID sql.NullInt64
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateSessionKVStoreRecord(ctx context.Context, arg UpdateSessionKVStoreRecordParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateSessionKVStoreRecord,
|
||||
func (q *Queries) UpdateGroupKVStoreRecord(ctx context.Context, arg UpdateGroupKVStoreRecordParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateGroupKVStoreRecord,
|
||||
arg.Value,
|
||||
arg.Key,
|
||||
arg.RuleID,
|
||||
arg.Perm,
|
||||
arg.SessionID,
|
||||
arg.GroupID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ CREATE TABLE IF NOT EXISTS features (
|
|||
CREATE UNIQUE INDEX IF NOT EXISTS features_name_idx ON features (name);
|
||||
|
||||
-- kvstores houses key-value pairs under various namespaces determined
|
||||
-- by the rule name, session ID, and feature name.
|
||||
-- by the rule name, group ID, and feature name.
|
||||
CREATE TABLE IF NOT EXISTS kvstores (
|
||||
-- The auto incrementing primary key.
|
||||
id INTEGER PRIMARY KEY,
|
||||
|
|
@ -35,15 +35,15 @@ CREATE TABLE IF NOT EXISTS kvstores (
|
|||
-- kv_store.
|
||||
rule_id BIGINT REFERENCES rules(id) NOT NULL,
|
||||
|
||||
-- The session ID that this kv_store belongs to.
|
||||
-- If this is set, then this kv_store is a session-specific
|
||||
-- The group ID that this kv_store belongs to.
|
||||
-- If this is set, then this kv_store is a session-group specific
|
||||
-- kv_store for the given rule.
|
||||
session_id BIGINT REFERENCES sessions(id) ON DELETE CASCADE,
|
||||
group_id BIGINT REFERENCES sessions(id) ON DELETE CASCADE,
|
||||
|
||||
-- The feature name that this kv_store belongs to.
|
||||
-- If this is set, then this kv_store is a feature-specific
|
||||
-- kvstore under the given session ID and rule name.
|
||||
-- If this is set, then session_id must also be set.
|
||||
-- kvstore under the given group ID and rule name.
|
||||
-- If this is set, then group_id must also be set.
|
||||
feature_id BIGINT REFERENCES features(id),
|
||||
|
||||
-- The key of the entry.
|
||||
|
|
@ -54,4 +54,4 @@ CREATE TABLE IF NOT EXISTS kvstores (
|
|||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS kvstores_lookup_idx
|
||||
ON kvstores (entry_key, rule_id, perm, session_id, feature_id);
|
||||
ON kvstores (entry_key, rule_id, perm, group_id, feature_id);
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ type Kvstore struct {
|
|||
ID int64
|
||||
Perm bool
|
||||
RuleID int64
|
||||
SessionID sql.NullInt64
|
||||
GroupID sql.NullInt64
|
||||
FeatureID sql.NullInt64
|
||||
EntryKey string
|
||||
Value []byte
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ type Querier interface {
|
|||
DeleteAllTempKVStores(ctx context.Context) error
|
||||
DeleteFeatureKVStoreRecord(ctx context.Context, arg DeleteFeatureKVStoreRecordParams) error
|
||||
DeleteGlobalKVStoreRecord(ctx context.Context, arg DeleteGlobalKVStoreRecordParams) error
|
||||
DeleteSessionKVStoreRecord(ctx context.Context, arg DeleteSessionKVStoreRecordParams) error
|
||||
DeleteGroupKVStoreRecord(ctx context.Context, arg DeleteGroupKVStoreRecordParams) error
|
||||
DeleteSessionsWithState(ctx context.Context, state int16) error
|
||||
GetAccount(ctx context.Context, id int64) (Account, error)
|
||||
GetAccountByLabel(ctx context.Context, label sql.NullString) (Account, error)
|
||||
|
|
@ -29,6 +29,7 @@ type Querier interface {
|
|||
GetFeatureID(ctx context.Context, name string) (int64, error)
|
||||
GetFeatureKVStoreRecord(ctx context.Context, arg GetFeatureKVStoreRecordParams) ([]byte, error)
|
||||
GetGlobalKVStoreRecord(ctx context.Context, arg GetGlobalKVStoreRecordParams) ([]byte, error)
|
||||
GetGroupKVStoreRecord(ctx context.Context, arg GetGroupKVStoreRecordParams) ([]byte, error)
|
||||
GetOrInsertFeatureID(ctx context.Context, name string) (int64, error)
|
||||
GetOrInsertRuleID(ctx context.Context, name string) (int64, error)
|
||||
GetPseudoForReal(ctx context.Context, arg GetPseudoForRealParams) (string, error)
|
||||
|
|
@ -40,7 +41,6 @@ type Querier interface {
|
|||
GetSessionByLocalPublicKey(ctx context.Context, localPublicKey []byte) (Session, error)
|
||||
GetSessionFeatureConfigs(ctx context.Context, sessionID int64) ([]SessionFeatureConfig, error)
|
||||
GetSessionIDByAlias(ctx context.Context, alias []byte) (int64, error)
|
||||
GetSessionKVStoreRecord(ctx context.Context, arg GetSessionKVStoreRecordParams) ([]byte, error)
|
||||
GetSessionMacaroonCaveats(ctx context.Context, sessionID int64) ([]SessionMacaroonCaveat, error)
|
||||
GetSessionMacaroonPermissions(ctx context.Context, sessionID int64) ([]SessionMacaroonPermission, error)
|
||||
GetSessionPrivacyFlags(ctx context.Context, sessionID int64) ([]SessionPrivacyFlag, error)
|
||||
|
|
@ -71,7 +71,7 @@ type Querier interface {
|
|||
UpdateAccountLastUpdate(ctx context.Context, arg UpdateAccountLastUpdateParams) (int64, error)
|
||||
UpdateFeatureKVStoreRecord(ctx context.Context, arg UpdateFeatureKVStoreRecordParams) error
|
||||
UpdateGlobalKVStoreRecord(ctx context.Context, arg UpdateGlobalKVStoreRecordParams) error
|
||||
UpdateSessionKVStoreRecord(ctx context.Context, arg UpdateSessionKVStoreRecordParams) error
|
||||
UpdateGroupKVStoreRecord(ctx context.Context, arg UpdateGroupKVStoreRecordParams) error
|
||||
UpdateSessionState(ctx context.Context, arg UpdateSessionStateParams) error
|
||||
UpsertAccountPayment(ctx context.Context, arg UpsertAccountPaymentParams) error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ FROM features
|
|||
WHERE name = sqlc.arg('name');
|
||||
|
||||
-- name: InsertKVStoreRecord :exec
|
||||
INSERT INTO kvstores (perm, rule_id, session_id, feature_id, entry_key, value)
|
||||
INSERT INTO kvstores (perm, rule_id, group_id, feature_id, entry_key, value)
|
||||
VALUES ($1, $2, $3, $4, $5, $6);
|
||||
|
||||
-- name: DeleteAllTempKVStores :exec
|
||||
|
|
@ -38,16 +38,16 @@ FROM kvstores
|
|||
WHERE entry_key = sqlc.arg('key')
|
||||
AND rule_id = sqlc.arg('rule_id')
|
||||
AND perm = sqlc.arg('perm')
|
||||
AND session_id IS NULL
|
||||
AND group_id IS NULL
|
||||
AND feature_id IS NULL;
|
||||
|
||||
-- name: GetSessionKVStoreRecord :one
|
||||
-- name: GetGroupKVStoreRecord :one
|
||||
SELECT value
|
||||
FROM kvstores
|
||||
WHERE entry_key = sqlc.arg('key')
|
||||
AND rule_id = sqlc.arg('rule_id')
|
||||
AND perm = sqlc.arg('perm')
|
||||
AND session_id = sqlc.arg('session_id')
|
||||
AND group_id = sqlc.arg('group_id')
|
||||
AND feature_id IS NULL;
|
||||
|
||||
-- name: GetFeatureKVStoreRecord :one
|
||||
|
|
@ -56,7 +56,7 @@ FROM kvstores
|
|||
WHERE entry_key = sqlc.arg('key')
|
||||
AND rule_id = sqlc.arg('rule_id')
|
||||
AND perm = sqlc.arg('perm')
|
||||
AND session_id = sqlc.arg('session_id')
|
||||
AND group_id = sqlc.arg('group_id')
|
||||
AND feature_id = sqlc.arg('feature_id');
|
||||
|
||||
-- name: DeleteGlobalKVStoreRecord :exec
|
||||
|
|
@ -64,15 +64,15 @@ DELETE FROM kvstores
|
|||
WHERE entry_key = sqlc.arg('key')
|
||||
AND rule_id = sqlc.arg('rule_id')
|
||||
AND perm = sqlc.arg('perm')
|
||||
AND session_id IS NULL
|
||||
AND group_id IS NULL
|
||||
AND feature_id IS NULL;
|
||||
|
||||
-- name: DeleteSessionKVStoreRecord :exec
|
||||
-- name: DeleteGroupKVStoreRecord :exec
|
||||
DELETE FROM kvstores
|
||||
WHERE entry_key = sqlc.arg('key')
|
||||
AND rule_id = sqlc.arg('rule_id')
|
||||
AND perm = sqlc.arg('perm')
|
||||
AND session_id = sqlc.arg('session_id')
|
||||
AND group_id = sqlc.arg('group_id')
|
||||
AND feature_id IS NULL;
|
||||
|
||||
-- name: DeleteFeatureKVStoreRecord :exec
|
||||
|
|
@ -80,7 +80,7 @@ DELETE FROM kvstores
|
|||
WHERE entry_key = sqlc.arg('key')
|
||||
AND rule_id = sqlc.arg('rule_id')
|
||||
AND perm = sqlc.arg('perm')
|
||||
AND session_id = sqlc.arg('session_id')
|
||||
AND group_id = sqlc.arg('group_id')
|
||||
AND feature_id = sqlc.arg('feature_id');
|
||||
|
||||
-- name: UpdateGlobalKVStoreRecord :exec
|
||||
|
|
@ -89,16 +89,16 @@ SET value = $1
|
|||
WHERE entry_key = sqlc.arg('key')
|
||||
AND rule_id = sqlc.arg('rule_id')
|
||||
AND perm = sqlc.arg('perm')
|
||||
AND session_id IS NULL
|
||||
AND group_id IS NULL
|
||||
AND feature_id IS NULL;
|
||||
|
||||
-- name: UpdateSessionKVStoreRecord :exec
|
||||
-- name: UpdateGroupKVStoreRecord :exec
|
||||
UPDATE kvstores
|
||||
SET value = $1
|
||||
WHERE entry_key = sqlc.arg('key')
|
||||
AND rule_id = sqlc.arg('rule_id')
|
||||
AND perm = sqlc.arg('perm')
|
||||
AND session_id = sqlc.arg('session_id')
|
||||
AND group_id = sqlc.arg('group_id')
|
||||
AND feature_id IS NULL;
|
||||
|
||||
-- name: UpdateFeatureKVStoreRecord :exec
|
||||
|
|
@ -107,5 +107,5 @@ SET value = $1
|
|||
WHERE entry_key = sqlc.arg('key')
|
||||
AND rule_id = sqlc.arg('rule_id')
|
||||
AND perm = sqlc.arg('perm')
|
||||
AND session_id = sqlc.arg('session_id')
|
||||
AND group_id = sqlc.arg('group_id')
|
||||
AND feature_id = sqlc.arg('feature_id');
|
||||
|
|
|
|||
|
|
@ -22,13 +22,13 @@ type SQLKVStoreQueries interface {
|
|||
|
||||
DeleteFeatureKVStoreRecord(ctx context.Context, arg sqlc.DeleteFeatureKVStoreRecordParams) error
|
||||
DeleteGlobalKVStoreRecord(ctx context.Context, arg sqlc.DeleteGlobalKVStoreRecordParams) error
|
||||
DeleteSessionKVStoreRecord(ctx context.Context, arg sqlc.DeleteSessionKVStoreRecordParams) error
|
||||
DeleteGroupKVStoreRecord(ctx context.Context, arg sqlc.DeleteGroupKVStoreRecordParams) error
|
||||
GetFeatureKVStoreRecord(ctx context.Context, arg sqlc.GetFeatureKVStoreRecordParams) ([]byte, error)
|
||||
GetGlobalKVStoreRecord(ctx context.Context, arg sqlc.GetGlobalKVStoreRecordParams) ([]byte, error)
|
||||
GetSessionKVStoreRecord(ctx context.Context, arg sqlc.GetSessionKVStoreRecordParams) ([]byte, error)
|
||||
GetGroupKVStoreRecord(ctx context.Context, arg sqlc.GetGroupKVStoreRecordParams) ([]byte, error)
|
||||
UpdateFeatureKVStoreRecord(ctx context.Context, arg sqlc.UpdateFeatureKVStoreRecordParams) error
|
||||
UpdateGlobalKVStoreRecord(ctx context.Context, arg sqlc.UpdateGlobalKVStoreRecordParams) error
|
||||
UpdateSessionKVStoreRecord(ctx context.Context, arg sqlc.UpdateSessionKVStoreRecordParams) error
|
||||
UpdateGroupKVStoreRecord(ctx context.Context, arg sqlc.UpdateGroupKVStoreRecordParams) error
|
||||
InsertKVStoreRecord(ctx context.Context, arg sqlc.InsertKVStoreRecordParams) error
|
||||
DeleteAllTempKVStores(ctx context.Context) error
|
||||
GetOrInsertFeatureID(ctx context.Context, name string) (int64, error)
|
||||
|
|
@ -198,7 +198,7 @@ func (s *sqlKVStore) Get(ctx context.Context, key string) ([]byte, error) {
|
|||
//
|
||||
// NOTE: part of the KVStore interface.
|
||||
func (s *sqlKVStore) Set(ctx context.Context, key string, value []byte) error {
|
||||
ruleID, sessionID, featureID, err := s.genNamespaceFields(ctx, false)
|
||||
ruleID, groupID, featureID, err := s.genNamespaceFields(ctx, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -219,7 +219,7 @@ func (s *sqlKVStore) Set(ctx context.Context, key string, value []byte) error {
|
|||
Value: value,
|
||||
Perm: s.params.perm,
|
||||
RuleID: ruleID,
|
||||
SessionID: sessionID,
|
||||
GroupID: groupID,
|
||||
FeatureID: featureID,
|
||||
},
|
||||
)
|
||||
|
|
@ -233,26 +233,26 @@ func (s *sqlKVStore) Set(ctx context.Context, key string, value []byte) error {
|
|||
|
||||
// Otherwise, the key exists but the value needs to be updated.
|
||||
switch {
|
||||
case sessionID.Valid && featureID.Valid:
|
||||
case groupID.Valid && featureID.Valid:
|
||||
return s.queries.UpdateFeatureKVStoreRecord(
|
||||
ctx, sqlc.UpdateFeatureKVStoreRecordParams{
|
||||
Key: key,
|
||||
Value: value,
|
||||
Perm: s.params.perm,
|
||||
SessionID: sessionID,
|
||||
GroupID: groupID,
|
||||
RuleID: ruleID,
|
||||
FeatureID: featureID,
|
||||
},
|
||||
)
|
||||
|
||||
case sessionID.Valid:
|
||||
return s.queries.UpdateSessionKVStoreRecord(
|
||||
ctx, sqlc.UpdateSessionKVStoreRecordParams{
|
||||
Key: key,
|
||||
Value: value,
|
||||
Perm: s.params.perm,
|
||||
SessionID: sessionID,
|
||||
RuleID: ruleID,
|
||||
case groupID.Valid:
|
||||
return s.queries.UpdateGroupKVStoreRecord(
|
||||
ctx, sqlc.UpdateGroupKVStoreRecordParams{
|
||||
Key: key,
|
||||
Value: value,
|
||||
Perm: s.params.perm,
|
||||
GroupID: groupID,
|
||||
RuleID: ruleID,
|
||||
},
|
||||
)
|
||||
|
||||
|
|
@ -278,7 +278,7 @@ func (s *sqlKVStore) Del(ctx context.Context, key string) error {
|
|||
// Note: we pass in true here for "read-only" since because this is a
|
||||
// Delete, if the record does not exist, we don't need to create one.
|
||||
// But no need to error out if it doesn't exist.
|
||||
ruleID, sessionID, featureID, err := s.genNamespaceFields(ctx, true)
|
||||
ruleID, groupID, featureID, err := s.genNamespaceFields(ctx, true)
|
||||
if errors.Is(err, sql.ErrNoRows) ||
|
||||
errors.Is(err, session.ErrUnknownGroup) {
|
||||
|
||||
|
|
@ -288,24 +288,24 @@ func (s *sqlKVStore) Del(ctx context.Context, key string) error {
|
|||
}
|
||||
|
||||
switch {
|
||||
case sessionID.Valid && featureID.Valid:
|
||||
case groupID.Valid && featureID.Valid:
|
||||
return s.queries.DeleteFeatureKVStoreRecord(
|
||||
ctx, sqlc.DeleteFeatureKVStoreRecordParams{
|
||||
Key: key,
|
||||
Perm: s.params.perm,
|
||||
SessionID: sessionID,
|
||||
GroupID: groupID,
|
||||
RuleID: ruleID,
|
||||
FeatureID: featureID,
|
||||
},
|
||||
)
|
||||
|
||||
case sessionID.Valid:
|
||||
return s.queries.DeleteSessionKVStoreRecord(
|
||||
ctx, sqlc.DeleteSessionKVStoreRecordParams{
|
||||
Key: key,
|
||||
Perm: s.params.perm,
|
||||
SessionID: sessionID,
|
||||
RuleID: ruleID,
|
||||
case groupID.Valid:
|
||||
return s.queries.DeleteGroupKVStoreRecord(
|
||||
ctx, sqlc.DeleteGroupKVStoreRecordParams{
|
||||
Key: key,
|
||||
Perm: s.params.perm,
|
||||
GroupID: groupID,
|
||||
RuleID: ruleID,
|
||||
},
|
||||
)
|
||||
|
||||
|
|
@ -326,30 +326,30 @@ func (s *sqlKVStore) Del(ctx context.Context, key string) error {
|
|||
// get fetches the value under the given key from the underlying kv store given
|
||||
// the namespace fields.
|
||||
func (s *sqlKVStore) get(ctx context.Context, key string) ([]byte, error) {
|
||||
ruleID, sessionID, featureID, err := s.genNamespaceFields(ctx, true)
|
||||
ruleID, groupID, featureID, err := s.genNamespaceFields(ctx, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch {
|
||||
case sessionID.Valid && featureID.Valid:
|
||||
case groupID.Valid && featureID.Valid:
|
||||
return s.queries.GetFeatureKVStoreRecord(
|
||||
ctx, sqlc.GetFeatureKVStoreRecordParams{
|
||||
Key: key,
|
||||
Perm: s.params.perm,
|
||||
SessionID: sessionID,
|
||||
GroupID: groupID,
|
||||
RuleID: ruleID,
|
||||
FeatureID: featureID,
|
||||
},
|
||||
)
|
||||
|
||||
case sessionID.Valid:
|
||||
return s.queries.GetSessionKVStoreRecord(
|
||||
ctx, sqlc.GetSessionKVStoreRecordParams{
|
||||
Key: key,
|
||||
Perm: s.params.perm,
|
||||
SessionID: sessionID,
|
||||
RuleID: ruleID,
|
||||
case groupID.Valid:
|
||||
return s.queries.GetGroupKVStoreRecord(
|
||||
ctx, sqlc.GetGroupKVStoreRecordParams{
|
||||
Key: key,
|
||||
Perm: s.params.perm,
|
||||
GroupID: groupID,
|
||||
RuleID: ruleID,
|
||||
},
|
||||
)
|
||||
|
||||
|
|
@ -373,7 +373,7 @@ func (s *sqlKVStore) genNamespaceFields(ctx context.Context,
|
|||
readOnly bool) (int64, sql.NullInt64, sql.NullInt64, error) {
|
||||
|
||||
var (
|
||||
sessionID sql.NullInt64
|
||||
groupID sql.NullInt64
|
||||
featureID sql.NullInt64
|
||||
ruleID int64
|
||||
err error
|
||||
|
|
@ -382,8 +382,8 @@ func (s *sqlKVStore) genNamespaceFields(ctx context.Context,
|
|||
// If a group ID is specified, then we first check that this group ID
|
||||
// is a known session alias.
|
||||
s.params.groupID.WhenSome(func(id session.ID) {
|
||||
var groupID int64
|
||||
groupID, err = s.queries.GetSessionIDByAlias(ctx, id[:])
|
||||
var dbGroupID int64
|
||||
dbGroupID, err = s.queries.GetSessionIDByAlias(ctx, id[:])
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
err = session.ErrUnknownGroup
|
||||
|
||||
|
|
@ -392,20 +392,20 @@ func (s *sqlKVStore) genNamespaceFields(ctx context.Context,
|
|||
return
|
||||
}
|
||||
|
||||
sessionID = sql.NullInt64{
|
||||
Int64: groupID,
|
||||
groupID = sql.NullInt64{
|
||||
Int64: dbGroupID,
|
||||
Valid: true,
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
return ruleID, sessionID, featureID, err
|
||||
return ruleID, groupID, featureID, err
|
||||
}
|
||||
|
||||
// We only insert a new rule name into the DB if this is a write call.
|
||||
if readOnly {
|
||||
ruleID, err = s.queries.GetRuleID(ctx, s.params.ruleName)
|
||||
if err != nil {
|
||||
return 0, sessionID, featureID,
|
||||
return 0, groupID, featureID,
|
||||
fmt.Errorf("unable to get rule ID: %w", err)
|
||||
}
|
||||
} else {
|
||||
|
|
@ -413,7 +413,7 @@ func (s *sqlKVStore) genNamespaceFields(ctx context.Context,
|
|||
ctx, s.params.ruleName,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, sessionID, featureID,
|
||||
return 0, groupID, featureID,
|
||||
fmt.Errorf("unable to get or insert rule "+
|
||||
"ID: %w", err)
|
||||
}
|
||||
|
|
@ -441,5 +441,5 @@ func (s *sqlKVStore) genNamespaceFields(ctx context.Context,
|
|||
}
|
||||
})
|
||||
|
||||
return ruleID, sessionID, featureID, err
|
||||
return ruleID, groupID, featureID, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue