How do I execute a raw SQL file from a rake task? Right now I have
this:
require 'active_record'
desc "Get all the pico HTML mess into a Ruby model"
task :muck => :environment do
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
puts "About to process 'uge SQL file...\n"
execute "#{RAILS_ROOT}/db/html_template.sql"
puts "File executed\n"
end
But when I try it, I get this error:
undefined method `execute' for main:Object
Anyone know how to use a raw sql file in a rake task?
How do I execute a raw SQL file from a rake task? Right now I have
this:
require 'active_record'
desc "Get all the pico HTML mess into a Ruby model"
task :muck => :environment do
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
puts "About to process 'uge SQL file...\n"
execute "#{RAILS_ROOT}/db/html_template.sql"
puts "File executed\n"
end
But when I try it, I get this error:
undefined method `execute' for main:Object
That seems to work if actual sql code is put in the parenthesis, but how
can I run SQL out of a sql file in the rake task?
Doing this in the rake task:
ActiveRecord::Base.connection.execute("#{RAILS_ROOT}/db/html_template.sql")
gives me this error:
rake aborted!
Mysql::Error: You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near '/projects/trieste2/db/html_template.sql' at line 1:
/projects/trieste2/db/html_template.sql