-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add database table and methods for profile selectors (#3731)
* Add the selectors table Adds the table for the profile selectors. Related: #3720 * Add DB methods for selector management Adds the needed SQL methods to manage profile selectors Fixes: #3720
- Loading branch information
Showing
8 changed files
with
570 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- Copyright 2024 Stacklok, Inc | ||
-- | ||
-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
-- you may not use this file except in compliance with the License. | ||
-- You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
|
||
BEGIN; | ||
|
||
-- drop the index on the project column | ||
DROP INDEX IF EXISTS idx_profile_selectors_on_profile; | ||
|
||
-- drop the profile_selectors table | ||
DROP TABLE IF EXISTS profile_selectors; | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-- Copyright 2024 Stacklok, Inc | ||
-- | ||
-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
-- you may not use this file except in compliance with the License. | ||
-- You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
|
||
BEGIN; | ||
|
||
CREATE TABLE IF NOT EXISTS profile_selectors ( | ||
id UUID NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY, | ||
profile_id UUID NOT NULL REFERENCES profiles(id) ON DELETE CASCADE, | ||
entity entities, -- this is nullable since it can be applicable to all | ||
selector TEXT NOT NULL, -- CEL expression | ||
comment TEXT NOT NULL -- optional comment (can be empty string) | ||
); | ||
|
||
-- Ensure we have performant search based on profile_id | ||
CREATE INDEX idx_profile_selectors_on_profile ON profile_selectors(profile_id); | ||
|
||
COMMIT; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-- name: CreateSelector :one | ||
INSERT INTO profile_selectors (profile_id, entity, selector, comment) | ||
VALUES ($1, $2, $3, $4) | ||
RETURNING id, profile_id, entity, selector, comment; | ||
|
||
-- name: GetSelectorsByProfileID :many | ||
SELECT id, profile_id, entity, selector, comment | ||
FROM profile_selectors | ||
WHERE profile_id = $1; | ||
|
||
-- name: UpdateSelector :one | ||
UPDATE profile_selectors | ||
SET entity = $2, selector = $3, comment = $4 | ||
WHERE id = $1 | ||
RETURNING id, profile_id, entity, selector, comment; | ||
|
||
-- name: DeleteSelector :exec | ||
DELETE FROM profile_selectors | ||
WHERE id = $1; | ||
|
||
-- name: GetSelectorByID :one | ||
SELECT id, profile_id, entity, selector, comment | ||
FROM profile_selectors | ||
WHERE id = $1; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.