Skip to content

Instantly share code, notes, and snippets.

@pedromtavares
Created May 28, 2010 13:43
Show Gist options
  • Save pedromtavares/417159 to your computer and use it in GitHub Desktop.
Save pedromtavares/417159 to your computer and use it in GitHub Desktop.
desc "Move paths to more specific tables."
task :path_moving => :environment do
filetemp = "tmp/temp.sql"
File.open(filetemp, 'w') do |file|
Path.paginated_each do |path|
if path.user_agent =~ /[B|b]ot|[B|b]aidu|[S|s]pider/
file.puts "insert into `spiders_paths` (#{path.attribute_names.map{|attr| "`#{attr}`"}.join(', ')})
values(#{path.attribute_names.map{|attr| "#{path.send(attr).blank? ? 'NULL' : "'#{path.send(attr).to_s.gsub(/[']/, '\\\\\'')}'"}"}.join(', ')});\n"
else
file.puts << "insert into `customers_paths` (#{path.attribute_names.map{|attr| "`#{attr}`"}.join(', ')})
values(#{path.attribute_names.map{|attr| "#{path.send(attr).blank? ? 'NULL' : "'#{path.send(attr).to_s.gsub(/[']/, '\\\\\'')}'"}"}.join(', ')});\n"
end
end
end
system("mysql -u root usedcisco_development < #{filetemp}")
File.delete(filetemp)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment