1 class AddNotesAndDiaryCommentsCounterCaches < ActiveRecord::Migration[7.1]
3 add_column :users, :diary_comments_count, :integer, :default => 0
4 add_column :users, :note_comments_count, :integer, :default => 0
6 users_with_diary_comments = DiaryComment.distinct.pluck(:user_id)
7 users_with_diary_comments.each do |user_id|
8 User.reset_counters(user_id, :diary_comments)
11 users_with_note_comments = NoteComment.where.not(:author_id => nil).distinct.pluck(:author_id)
12 users_with_note_comments.each do |author_id|
13 User.reset_counters(author_id, :note_comments)
18 remove_column :users, :diary_comments_count
19 remove_column :users, :note_comments_count