Assert event not deleted on add_events_per_week migration

This commit is contained in:
Chrisbr 2014-07-24 11:05:03 +02:00
parent 3e5a089eb1
commit c05b428d8c

View file

@ -17,8 +17,10 @@ class AddEventsPerWeekToConference < ActiveRecord::Migration
add_column :conferences, :events_per_week, :text add_column :conferences, :events_per_week, :text
TempVersion.where(item_type: 'Event').each do |event_version| TempVersion.where(item_type: 'Event').each do |event_version|
event = TempEvent.find(event_version.item_id) event = TempEvent.find_by_id(event_version.item_id)
conference = TempConference.find(event.conference_id) if event
conference = TempConference.find_by_id(event.conference_id)
if conference
week = event_version.created_at.end_of_week week = event_version.created_at.end_of_week
no_events = { no_events = {
@ -64,10 +66,12 @@ class AddEventsPerWeekToConference < ActiveRecord::Migration
end end
conference.save conference.save
end end
end
end
# Cumulate the previous weeks to get a snapshot # Cumulate the previous weeks to get a snapshot
TempConference.all.each do |conference| TempConference.all.each do |conference|
hash = conference.events_per_week.sort.to_hash hash = conference.events_per_week.sort.to_h
previous = nil previous = nil
hash.each do |week, values| hash.each do |week, values|