From 6f6e827702fb2e56c0f7cd6aaf43d98f9c7f5fb2 Mon Sep 17 00:00:00 2001 From: Nick Black Date: Wed, 23 Jan 2008 18:39:29 +0000 Subject: [PATCH] added task to add version numbers to nodes table --- lib/tasks/add_version_to_nodes.rake | 45 +++++++++++++++++++++++++++++ lib/tasks/populate_node_tags.rake | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 lib/tasks/add_version_to_nodes.rake diff --git a/lib/tasks/add_version_to_nodes.rake b/lib/tasks/add_version_to_nodes.rake new file mode 100644 index 000000000..1ec831234 --- /dev/null +++ b/lib/tasks/add_version_to_nodes.rake @@ -0,0 +1,45 @@ +namespace 'db' do + desc 'Populate the node_tags 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 = {} + + 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 + end + + hash.each_value do |node_array| + n = 1 + node_array.each do |node| + temp_old_node = TempOldNode.new + temp_old_node.id = node.id + temp_old_node.latitude = node.latitude + temp_old_node.longitude = node.longitude + temp_old_node.user_id = node.user_id + 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 +=1 + end + end + lower_bound += increment + end + end +end + + + + + + diff --git a/lib/tasks/populate_node_tags.rake b/lib/tasks/populate_node_tags.rake index fe247da03..6a57dffc5 100644 --- a/lib/tasks/populate_node_tags.rake +++ b/lib/tasks/populate_node_tags.rake @@ -6,7 +6,7 @@ namespace 'db' do node_count = Node.count limit = 1000 #the number of nodes to grab in one go offset = 0 - + while offset < node_count Node.find(:all, :limit => limit, :offset => offset).each do |node| seq_id = 1 -- 2.43.2