openstreetmap-website/db/migrate/20121005195010_add_diary_entry_counter_caches.rb
Andy Allan d130db9fa8 Avoid more models in old migrations
Although these migrations run fine today, they could break in the future
if changes are made to the current model code.
2019-07-17 12:16:20 +02:00

19 lines
456 B
Ruby

class AddDiaryEntryCounterCaches < ActiveRecord::Migration[4.2]
class DiaryEntry < ActiveRecord::Base
end
class User < ActiveRecord::Base
end
def self.up
add_column :users, :diary_entries_count, :integer, :null => false, :default => 0
DiaryEntry.group(:user_id).pluck(:user_id).each do |user_id|
User.reset_counters(user_id, :diary_entries)
end
end
def self.down
remove_column :users, :diary_entries_count
end
end