Skip to content

Commit

Permalink
Fix migrated column on rule evaluations (#4102)
Browse files Browse the repository at this point in the history
After testing in staging, I found that the migration to set the
`migrated` column did not work as expected. The intention was that any rows in
`rule_evaluations` which have the same combination of rule instance ids
and entity ids should be marked as migrated, as they refer to the same
evaluations. This migration addresses this problem.

Tested against staging (with a rollback)
  • Loading branch information
dmjb committed Aug 7, 2024
1 parent 227c5f3 commit f99bc08
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
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.

-- Nothing to undo
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-- 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;

UPDATE rule_evaluations AS re
SET migrated = TRUE
FROM evaluation_rule_entities AS ere
WHERE re.entity = 'pull_request'::entities
AND ere.entity_type = 'pull_request'::entities
AND ere.pull_request_id = re.pull_request_id
AND re.migrated = FALSE;

UPDATE rule_evaluations AS re
SET migrated = TRUE
FROM evaluation_rule_entities AS ere
WHERE re.entity = 'artifact'::entities
AND ere.entity_type = 'artifact'::entities
AND ere.artifact_id = re.artifact_id
AND re.migrated = FALSE;

UPDATE rule_evaluations AS re
SET migrated = TRUE
FROM evaluation_rule_entities AS ere
WHERE re.entity = 'repository'::entities
AND ere.entity_type = 'repository'::entities
AND ere.repository_id = re.repository_id
AND re.migrated = FALSE;

COMMIT;

0 comments on commit f99bc08

Please sign in to comment.