Skip to content

Instantly share code, notes, and snippets.

@brookr
Created November 9, 2009 17:44
Show Gist options
  • Save brookr/230124 to your computer and use it in GitHub Desktop.
Save brookr/230124 to your computer and use it in GitHub Desktop.
def load_sql_file(file)
config = ActiveRecord::Base.configurations[RAILS_ENV]
database = config['database']
user = config['username']
puts `psql -U #{user} -f #{file} #{database}`
end
desc 'Load an SQL file'
task :load_sql => [ENV['FILE'], :environment] do |t|
file = ENV['FILE']
file = RAILS_ROOT + "/" + file unless file[0].chr == '/'
load_sql_file file
end
(Source: http://web.archive.org/web/20060624132248/www.flpr.org/articles/2006/02/11/rake-task-to-load-sql)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment