Sha256: 1ac40e817444dfcca1342a7e3ba8e3a2b3cf3aed6849746def5ac14a82dcbea1
Contents?: true
Size: 1.02 KB
Versions: 6
Compression:
Stored size: 1.02 KB
Contents
namespace :db do desc "Dump the current database to db/data.sql" task :dump => :environment do mysqldump = `which mysqldump`.strip raise RuntimeError, "Cannot find mysqldump." if mysqldump.blank? sh "#{mysqldump} -e #{mysql_options} > #{file_path}" end desc "Load the db/data.sql data into the current database." task :load => ["db:drop", "db:create"] do mysql = `which mysql`.strip raise RuntimeError, "Cannot find mysql." if mysql.blank? sh "#{mysql} #{mysql_options} < #{file_path}" end def file_path "db/data.sql" end def mysql_options config = ActiveRecord::Base.configurations[Rails.env || "development"] raise RuntimeError, "I only work with mysql." unless config["adapter"].starts_with? "mysql" options = " -u #{config["username"]}" options += " -p'#{config["password"]}'" if config["password"] options += " -h #{config["host"]}" if config["host"] options += " -S #{config["socket"]}" if config["socket"] options += " '#{config["database"]}'" end end
Version data entries
6 entries across 6 versions & 1 rubygems