-
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.
Fix migrated column on rule evaluations (#4102)
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
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
database/migrations/000087_set_migrated_flag_rule_evaluations.down.sql
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,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 |
41 changes: 41 additions & 0 deletions
41
database/migrations/000087_set_migrated_flag_rule_evaluations.up.sql
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,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; |