X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/2ce81773333d55fe366fd8a0bc754a23d909944e..f2c955a96a5df1eb74746699f4d327527a3ac8c6:/lib/tasks/add_version_to_nodes.rake?ds=inline diff --git a/lib/tasks/add_version_to_nodes.rake b/lib/tasks/add_version_to_nodes.rake index 990ce5c4c..cdcf13a3e 100644 --- a/lib/tasks/add_version_to_nodes.rake +++ b/lib/tasks/add_version_to_nodes.rake @@ -1,20 +1,19 @@ -namespace 'db' do - desc 'Adds a version number to the noes table' +namespace "db" do + desc "Adds a version number to the nodes table" task :node_version do - require File.dirname(__FILE__) + '/../../config/environment' + require File.dirname(__FILE__) + "/../../config/environment" - lower_bound = 0 - increment = 100 - node_count = OldNode.count - puts node_count - - while lower_bound < node_count - upper_bound = lower_bound + increment - hash = {} + increment = 1000 + offset = 0 + id_max = OldNode.find(:first, :order => "id desc").id - OldNode.find(:all, :conditions => ['id >= ? AND id < ?',lower_bound, upper_bound], :order => 'timestamp').each do |node| - hash[node.id] = [] if hash[node.id].nil? - hash[node.id] << node + while offset < (id_max + increment) + hash = {} + + # should be offsetting not selecting + OldNode.find(:all, :limit => increment, :offset => offset, :order => "timestamp").each do |node| + hash[node.id] ||= [] + hash[node.id] << node end hash.each_value do |node_array| @@ -29,17 +28,11 @@ namespace 'db' do temp_old_node.timestamp = node.timestamp temp_old_node.tile = node.tile temp_old_node.version = n - temp_old_node.save! || raise - n +=1 + temp_old_node.save! || fail + n += 1 end end - lower_bound += increment + offset += increment end end end - - - - - -