diff --git a/database/migrations/000076_evaluation_entity_type.down.sql b/database/migrations/000076_evaluation_entity_type.down.sql new file mode 100644 index 0000000000..d210482ddd --- /dev/null +++ b/database/migrations/000076_evaluation_entity_type.down.sql @@ -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; diff --git a/database/migrations/000076_evaluation_entity_type.up.sql b/database/migrations/000076_evaluation_entity_type.up.sql new file mode 100644 index 0000000000..d11811deaf --- /dev/null +++ b/database/migrations/000076_evaluation_entity_type.up.sql @@ -0,0 +1,16 @@ +-- 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. + +-- this will be made non-nullable in a future PR +ALTER TABLE evaluation_rule_entities ADD COLUMN entity_type entities; diff --git a/database/query/eval_history.sql b/database/query/eval_history.sql index 47888f7edf..24fe9c7d10 100644 --- a/database/query/eval_history.sql +++ b/database/query/eval_history.sql @@ -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; diff --git a/internal/db/eval_history.sql.go b/internal/db/eval_history.sql.go index 8ffde4899c..f7a6e0b97c 100644 --- a/internal/db/eval_history.sql.go +++ b/internal/db/eval_history.sql.go @@ -103,12 +103,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 ` @@ -118,6 +120,7 @@ type InsertEvaluationRuleEntityParams struct { RepositoryID uuid.NullUUID `json:"repository_id"` PullRequestID uuid.NullUUID `json:"pull_request_id"` ArtifactID uuid.NullUUID `json:"artifact_id"` + EntityType NullEntities `json:"entity_type"` } func (q *Queries) InsertEvaluationRuleEntity(ctx context.Context, arg InsertEvaluationRuleEntityParams) (uuid.UUID, error) { @@ -126,6 +129,7 @@ func (q *Queries) InsertEvaluationRuleEntity(ctx context.Context, arg InsertEval arg.RepositoryID, arg.PullRequestID, arg.ArtifactID, + arg.EntityType, ) var id uuid.UUID err := row.Scan(&id) diff --git a/internal/db/models.go b/internal/db/models.go index 5d13b950ed..252e8c85d7 100644 --- a/internal/db/models.go +++ b/internal/db/models.go @@ -491,6 +491,7 @@ type EvaluationRuleEntity struct { RepositoryID uuid.NullUUID `json:"repository_id"` PullRequestID uuid.NullUUID `json:"pull_request_id"` ArtifactID uuid.NullUUID `json:"artifact_id"` + EntityType NullEntities `json:"entity_type"` } type EvaluationStatus struct { diff --git a/internal/history/service.go b/internal/history/service.go index a514084852..b1dfe3ed46 100644 --- a/internal/history/service.go +++ b/internal/history/service.go @@ -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 {