Created
September 8, 2010 16:21
-
-
Save ehq/570359 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.update_migration | |
all.each do |u| | |
begin | |
u.partner_id = Partner.first(:conditions => {name: u.partner_name}) | |
Timeline.all(:conditions => {user_id: u.pretty_id}).each do |t| | |
t.user_id = u.id | |
u.favorite_ids = [] | |
t.user_ids = [] | |
t.save | |
u.save! | |
end | |
rescue | |
puts "failed user: #{u.name}" | |
end | |
end | |
all.each do |u| | |
begin | |
u.favorites_pretty_ids.each do |id| | |
t = Timeline.find(:first, :conditions => {:pretty_id => id}) | |
u.favorites << t | |
end | |
u.save! | |
rescue | |
puts "failed user: #{u.name} (step 2)" | |
end | |
end | |
Source.all.each do |s| | |
begin | |
s.timeline_id = Timeline.first(condition: {pretty_id: s.timeline_id}) | |
s.save! | |
rescue | |
puts "failed source: #{s.id}" | |
end | |
end | |
Media.all.each do |m| | |
begin | |
m.event_ids = []; | |
m.source_id = Source.first(condition: {pretty_id: m.source_id}) | |
m.timeline_id = Timeline.first(condition: {pretty_id: m.timeline_id}) | |
m.save! | |
rescue | |
puts "failed media: #{m.id}" | |
end | |
end | |
Event.all.each do |e| | |
begin | |
e.user_id = User.first(conditions: {pretty_id: e.user_id}).id | |
e.timeline_id = Timeline.first(conditions: {pretty_id: e.timeline_id}).id | |
if e.closed == "1" | |
e.closed = true | |
else | |
e.closed = false | |
end | |
if e.private == "1" | |
e.private = true | |
else | |
e.private = false | |
end | |
if e.auto_approve_comments == "1" | |
e.auto_approve_comments = true | |
else | |
e.auto_approve_comments = false | |
end | |
e.invited_user_ids = [] | |
e.removed_user_ids = [] | |
e.invited_users_pretty_ids.each {|id| e.invited_users << User.first(conditions: {pretty_id: id})} | |
e.removed_users_pretty_ids.each {|id| e.removed_users << User.first(conditions: {pretty_id: id})} | |
e.medias_pretty_ids.each do |id| | |
m = Media.first(conditions: {pretty_id: id}) | |
e.media_ids = [] | |
e.medias << m | |
end | |
e.save! | |
rescue | |
puts "failed event: #{e.name}" | |
end | |
end | |
Comment.all.each do |c| | |
begin | |
c.user_id = User.first( conditions: {pretty_id: c.user_id}).id | |
c.event_id = Event.first(conditions: {pretty_id: c.event_id}).id | |
c.save! | |
rescue | |
puts "failed comment: #{c.id}" | |
end | |
end | |
Notification.all.each do |n| | |
begin | |
n.user_id = User.first( conditions: {pretty_id: n.user_id}).id | |
n.save! | |
rescue | |
puts "failed notification: #{n.id}" | |
end | |
end | |
Invitation.all.each do |n| | |
begin | |
n.user_id = User.first( conditions: {pretty_id: n.user_id}).id | |
n.save! | |
rescue | |
puts "failed invitation: #{n.id}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment