Execute sql script inside seed.rb in rails3

Bijendra picture Bijendra · Jun 3, 2011 · Viewed 9.4k times · Source

I want to execute this sql script inside my seed.rb

LOAD DATA LOCAL INFILE '/home/list-38.csv'
INTO TABLE list
FIELDS TERMINATED BY ':'
LINES TERMINATED BY '\n'
(email,name,password);

I checked this link but unable to figure out the solution.So that once we run rake db:seed

How to seed mysql database by running sql scripts in Ruby Rails platform? it dumps my data into the table.

any queries ..do reply

Thanx

Answer

Paul Groves picture Paul Groves · Jun 3, 2011

Try this in db/seeds.rb to execute raw SQL with rake db:seed

connection = ActiveRecord::Base.connection()
connection.execute("*_YOUR_SQL_HERE_*")