]> git.openstreetmap.org Git - rails.git/blob - lib/tasks/populate_node_tags.rake
Add a check to make sure that a node/way/relation doesn't already exist in the relati...
[rails.git] / lib / tasks / populate_node_tags.rake
1 namespace 'db' do
2   desc 'Populate the node_tags table'
3   task :node_tags  do
4     require File.dirname(__FILE__) + '/../../config/environment'
5
6     node_count = Node.count
7     limit = 1000 #the number of nodes to grab in one go
8     offset = 0   
9
10     while offset < node_count
11         Node.find(:all, :limit => limit, :offset => offset).each do |node|
12         seq_id = 1
13         node.tags.split(';').each do |tag|
14           nt = NodeTag.new
15           nt.id = node.id
16           nt.k = tag.split('=')[0] || ''
17           nt.v = tag.split('=')[1] || ''
18           nt.sequence_id = seq_id 
19           nt.save! || raise
20           seq_id += 1
21         end
22
23         version = 1 #version refers to one set of histories
24         node.old_nodes.find(:all, :order => 'timestamp asc').each do |old_node|
25         sequence_id = 1 #sequence_id refers to the sequence of node tags within a history
26         old_node.tags.split(';').each do |tag|
27           ont = OldNodeTag.new
28           ont.id = node.id #the id of the node tag
29           ont.k = tag.split('=')[0] || ''
30           ont.v = tag.split('=')[1] || ''
31           ont.version = version
32           ont.sequence_id = sequence_id
33           ont.save! || raise
34           sequence_id += 1
35           end     
36         version += 1
37         end
38       end
39     offset += limit
40     end
41   end
42 end