]> git.openstreetmap.org Git - rails.git/blobdiff - lib/tasks/add_version_to_nodes.rake
Fix most auto-correctable rubocop issues
[rails.git] / lib / tasks / add_version_to_nodes.rake
index 1ec831234ca83b14ac57c624ecf62bda13e3a17e..c0fac49b70768f3c10c83148ca6cb17d7c94cd13 100644 (file)
@@ -1,20 +1,21 @@
 namespace 'db' do
-  desc 'Populate the node_tags table'
+  desc 'Adds a version number to the nodes table'
   task :node_version  do
     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|
+        if hash[node.id].nil?
+          hash[node.id] = []
+        end
+        hash[node.id] << node
       end
 
       hash.each_value do |node_array|
@@ -28,18 +29,12 @@ namespace 'db' do
           temp_old_node.visible = node.visible
           temp_old_node.timestamp = node.timestamp
           temp_old_node.tile = node.tile
-          temp_old_node.version = node.version
-          temp_old_node.save! || raise
-          n +=
+          temp_old_node.version = n
+          temp_old_node.save! || fail
+          n += 1
         end
       end
-      lower_bound += increment
+      offset += increment
     end
   end
 end
-
-
-
-
-
-