mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-14 21:24:54 +08:00
15 lines
492 B
Ruby
15 lines
492 B
Ruby
class AddCounterCacheToProtocols < ActiveRecord::Migration[4.2]
|
|
def up
|
|
add_column :protocols, :nr_of_synced_children, :integer, default: 0
|
|
|
|
# Okay, now initialize the values of synced children
|
|
Protocol.find_each do |protocol|
|
|
children_count = select_value("SELECT COUNT(*) FROM protocols WHERE parent_id=#{protocol.id};")
|
|
protocol.update(nr_of_synced_children: children_count)
|
|
end
|
|
end
|
|
|
|
def down
|
|
remove_column :protocols, :nr_of_synced_children
|
|
end
|
|
end
|