-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
591defc
commit 6a44fb4
Showing
4 changed files
with
27 additions
and
11 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
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,12 @@ | ||
class AddAutoflaggedToPosts < ActiveRecord::Migration[5.1] | ||
def change | ||
add_column :posts, :autoflagged, :boolean, default: false | ||
|
||
Post.where(id: (Post.left_joins(:flag_logs) | ||
.joins("LEFT JOIN (SELECT posts.id AS 'post_id', COUNT(DISTINCT flag_logs.id) AS 'autoflag_count' FROM posts INNER JOIN flag_logs " \ | ||
'ON flag_logs.post_id = posts.id WHERE flag_logs.is_auto = 1 GROUP BY posts.id) AS flag_counts ON flag_counts.post_id = posts.id') | ||
.where(flag_counts: { autoflag_count: 0 }) + | ||
Post.left_joins(:flag_logs).where(flag_logs: { post_id: nil })).map(&:id)).update_all(autoflagged: false) | ||
Post.joins(:flag_logs).where(flag_logs: { is_auto: true }).update_all(autoflagged: true) | ||
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
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