Created
May 28, 2010 13:43
-
-
Save pedromtavares/417159 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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