-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: avoid deprecated replace_flag API (#57)
`replace_flag` API will be deprecated. Therefore `malicious_file` score type must be entered into the database. In addition, migration is fixing IDs.
- Loading branch information
Showing
3 changed files
with
30 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
< 3.3.0.beta3-dev: d83344a719c21615690c620d2ddb98b5b1ca3cd8 | ||
< 3.3.0.beta1-dev: f0792d8bd3a275330045175cb064d5524f47dc11 | ||
3.1.999: 50177ed0e00b8e2c744267b727fb05784f0d4776 |
29 changes: 29 additions & 0 deletions
29
db/migrate/20240527061406_add_malicious_file_score_type.rb
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,29 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddMaliciousFileScoreType < ActiveRecord::Migration[7.0] | ||
def change | ||
result = DB.query <<~SQL | ||
SELECT MAX(position) FROM flags | ||
SQL | ||
|
||
position = result.last&.max | ||
|
||
result = DB.query <<~SQL | ||
INSERT INTO flags(name, name_key, applies_to, score_type, position, created_at, updated_at) | ||
VALUES ('Malicious File', 'malicious_file', '{}', true, #{position.to_i + 1}, NOW(), NOW()) | ||
RETURNING flags.id | ||
SQL | ||
|
||
new_score_id = result.last&.id | ||
|
||
DB.exec <<~SQL | ||
UPDATE reviewable_scores rs1 | ||
SET reviewable_score_type = #{new_score_id} | ||
FROM reviewable_scores rs2 | ||
LEFT JOIN reviewables ON reviewables.id = rs2.reviewable_id | ||
WHERE rs2.reason = 'malicious_file' | ||
AND reviewables.type = 'ReviewableUpload' | ||
AND rs1.id = rs2.id | ||
SQL | ||
end | ||
end |
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