Skip to content

Instantly share code, notes, and snippets.

@cyx
Created September 24, 2008 17:20
Show Gist options
  • Save cyx/12614 to your computer and use it in GitHub Desktop.
Save cyx/12614 to your computer and use it in GitHub Desktop.
class AddProjectIdToVotes < ActiveRecord::Migration
def self.up
# add_column :votes, :project_id, :integer
DbCluster.each do |c|
puts "Executing in #{c.connection_name}"
Line::Version.find(:all).each do |line_version|
Vote.find(:all, :conditions => { :voteable_type => 'Line::Version', :voteable_id => line_version.id }).each do |vote|
if line_version.project_id
Vote.update_all("voteable_id = '#{line_version.guid}', project_id = #{line_version.project_id}",
"id = #{vote.id}"
)
end
end
end
end
end
def self.down
remove_column :votes, :project_id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment