2015-11-03 14:36:44 -05:00
|
|
|
class AddLinksCounterCacheToCards < ActiveRecord::Migration
|
|
|
|
def up
|
|
|
|
add_column :cards, :links_count, :integer, default: 0, null: false
|
|
|
|
|
2015-11-03 15:37:21 -05:00
|
|
|
PaperTrail.whodunnit = 1
|
2015-11-03 14:36:44 -05:00
|
|
|
Card.reset_column_information
|
|
|
|
Card.find_each do |card|
|
|
|
|
card.update_attribute(:links_count, card.links.count)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
remove_column :cards, :links_count
|
|
|
|
end
|
|
|
|
end
|