brookr (owner)

Revisions

gist: 230124 Download_button fork
public
Public Clone URL: git://gist.github.com/230124.git
Embed All Files: show embed
SQL as Rake Task #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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)