Skip to content
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

Log evaluation history in new tables #3659

Merged
merged 3 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions database/mock/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions database/query/eval_history.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
-- 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.

-- name: GetLatestEvalStateForRuleEntity :one
SELECT eh.* FROM evaluation_rule_entities AS re
JOIN latest_evaluation_statuses AS les ON les.rule_entity_id = re.id
JOIN evaluation_statuses AS eh ON les.evaluation_history_id = eh.id
WHERE re.rule_id = $1
AND (
re.repository_id = $2
OR re.pull_request_id = $3
OR re.artifact_id = $4
)
FOR UPDATE;

-- name: InsertEvaluationRuleEntity :one
INSERT INTO evaluation_rule_entities(
rule_id,
repository_id,
pull_request_id,
artifact_id
) VALUES (
$1,
$2,
$3,
$4
)
RETURNING id;

-- name: InsertEvaluationStatus :one
INSERT INTO evaluation_statuses(
rule_entity_id,
status,
details
) VALUES (
$1,
$2,
$3
)
RETURNING id;

-- name: UpdateEvaluationTimes :exec
UPDATE evaluation_statuses
SET
evaluation_times = $1,
most_recent_evaluation = NOW()
WHERE id = $2;

-- name: UpsertLatestEvaluationStatus :exec
INSERT INTO latest_evaluation_statuses(
rule_entity_id,
evaluation_history_id
) VALUES (
$1,
$2
)
ON CONFLICT (rule_entity_id, evaluation_history_id) DO UPDATE
SET evaluation_history_id = $2;
8 changes: 7 additions & 1 deletion database/query/rule_instances.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@ SELECT * FROM rule_instances WHERE profile_id = $1 AND entity_type = $2;
DELETE FROM rule_instances
WHERE profile_id = $1
AND entity_type = $2
AND NOT id = ANY(sqlc.arg(updated_ids)::UUID[]);
AND NOT id = ANY(sqlc.arg(updated_ids)::UUID[]);

-- name: GetIDByProfileEntityName :one
SELECT id FROM rule_instances
WHERE profile_id = $1
AND entity_type = $2
AND name = $3;
167 changes: 167 additions & 0 deletions internal/db/eval_history.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading