public
Created — forked from alg/db.rb

  • Download Gist
lib/tasks/db.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
namespace :db do
 
desc 'Seed database from db/seed.sql file instead of the traditional db/seed.rb'
namespace :seed do
config = Rails::Configuration.new.database_configuration[RAILS_ENV]
seed_sql = File.expand_path(File.dirname(__FILE__) + '/../../db/seed.sql')
 
if !File.exists?(seed_sql)
puts "Missing RAILS_ROOT/db/seed.sql"
else
case config['adapter']
when 'mysql'
database = config['database']
username = config['username']
password = config['password']
`mysql #{database} -u#{username} -p#{password} < #{seed_sql}`
when 'sqlite3'
database = config['database']
`sqlite3 #{database} < #{seed_sql}`
else
puts "Wrong adapter. Only MySQL and Sqlite3 are supported."
end
end
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.