Skip to content

Commit

Permalink
Add entity_type column to evaluation_rule_entities
Browse files Browse the repository at this point in the history
This simplifies some queries which I am working on in another PR.
  • Loading branch information
dmjb committed Jul 24, 2024
1 parent b5ec456 commit cdc117d
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 4 deletions.
15 changes: 15 additions & 0 deletions database/migrations/000076_evaluation_entity_type.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- 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.

ALTER TABLE evaluation_rule_entities DROP COLUMN entity_type;
29 changes: 29 additions & 0 deletions database/migrations/000076_evaluation_entity_type.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- 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;

ALTER TABLE evaluation_rule_entities ADD COLUMN entity_type entities;

UPDATE evaluation_rule_entities
SET entity_type = (CASE
WHEN pull_request_id IS NOT NULL
THEN 'pull_request'::entities
WHEN artifact_id IS NOT NULL
THEN 'artifact'::entities
WHEN repository_id IS NOT NULL
THEN 'repository'::entities
END);

COMMIT;
6 changes: 4 additions & 2 deletions database/query/eval_history.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ INSERT INTO evaluation_rule_entities(
rule_id,
repository_id,
pull_request_id,
artifact_id
artifact_id,
entity_type
) VALUES (
$1,
$2,
$3,
$4
$4,
$5
)
RETURNING id;

Expand Down
8 changes: 6 additions & 2 deletions internal/db/eval_history.sql.go

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

1 change: 1 addition & 0 deletions internal/db/models.go

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

4 changes: 4 additions & 0 deletions internal/history/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ func (e *evaluationHistoryService) StoreEvaluationStatus(
RepositoryID: params.RepositoryID,
PullRequestID: params.PullRequestID,
ArtifactID: params.ArtifactID,
EntityType: db.NullEntities{
Entities: entityType,
Valid: true,
},
},
)
if err != nil {
Expand Down

0 comments on commit cdc117d

Please sign in to comment.