Created
January 28, 2014 10:23
-
-
Save pkuczynski/8665217 to your computer and use it in GitHub Desktop.
Loading data from SQL file in rake task
This file contains hidden or 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 '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