]> git.openstreetmap.org Git - rails.git/blob - lib/tasks/populate_node_tags.rake
rake task to populate node_tags and current_node_tags tables with values from the...
[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     #"created_by=YahooApplet 1.0;highway=traffic_signals"
7     node_count = Node.count
8  
9     for n in (0..node_count)
10       Node.find(:all, :limit => 1, :offset => n).each do |node|
11         seq_id = 1
12         node.tags.split(';').each do |tag|
13           nt = NodeTag.new
14           nt.id = node.id
15           nt.k = tag.split('=')[0]
16           nt.v = tag.split('=')[1]
17           nt.sequence_id = seq_id 
18           nt.save! || raise
19           seq_id += 1
20         end
21
22         version = 1 #version refers to one set of histories
23         node.old_nodes.find(:all, :order => 'timestamp asc').each do |old_node|
24         sequence_id = 1 #sequence_id refers to the sequence of node tags within a history
25         old_node.tags.split(';').each do |tag|
26           ont = OldNodeTag.new
27           ont.id = node.id #the id of the node tag
28           ont.k = tag.split('=')[0]
29           ont.v = tag.split('=')[1]
30           ont.version = version
31           ont.sequence_id = sequence_id
32           ont.save! || raise
33           sequence_id += 1
34           end     
35         version += 1
36         end
37       end
38     end
39   end
40 end