]> git.openstreetmap.org Git - rails.git/blob - lib/tasks/add_version_to_nodes.rake
Fix rubocop lint issues
[rails.git] / lib / tasks / add_version_to_nodes.rake
1 namespace 'db' do
2   desc 'Adds a version number to the nodes table'
3   task :node_version  do
4     require File.dirname(__FILE__) + '/../../config/environment'
5
6     increment = 1000
7     offset = 0
8     id_max = OldNode.find(:first, :order => 'id desc').id
9
10     while offset < (id_max + increment)
11       hash = {}
12
13       # should be offsetting not selecting
14       OldNode.find(:all, :limit => increment, :offset => offset, :order => 'timestamp').each do |node|
15         if hash[node.id].nil?
16           hash[node.id] = []
17         end
18         hash[node.id] << node
19       end
20
21       hash.each_value do |node_array|
22         n = 1
23         node_array.each do |node|
24           temp_old_node = TempOldNode.new
25           temp_old_node.id = node.id
26           temp_old_node.latitude = node.latitude
27           temp_old_node.longitude = node.longitude
28           temp_old_node.user_id = node.user_id
29           temp_old_node.visible = node.visible
30           temp_old_node.timestamp = node.timestamp
31           temp_old_node.tile = node.tile
32           temp_old_node.version = n
33           temp_old_node.save! || fail
34           n += 1
35         end
36       end
37       offset += increment
38     end
39   end
40 end