Skip to content

Instantly share code, notes, and snippets.

@pkuczynski
Created January 28, 2014 10:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkuczynski/8665217 to your computer and use it in GitHub Desktop.
Save pkuczynski/8665217 to your computer and use it in GitHub Desktop.
Loading data from SQL file in rake task
desc 'Load data from SQL file'
task :load_data => :environment do
puts 'Loading db/data.sql'
sql = File.read("#{Rails.root}/db/data.sql")
statements = sql.split(/;$/)
statements.pop # the last empty statement
statements.each do |statement|
ActiveRecord::Base.connection.execute(statement)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment