Created
September 12, 2010 23:08
-
-
Save rogerleite/576584 to your computer and use it in GitHub Desktop.
rake functions
This file contains 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
# Database Utils for lazy programmers | |
namespace :db do | |
# Simple Mysql Dump Operations | |
namespace :dump do | |
def param_filename | |
filename = ENV["file"] || "db/dump/#{db[:database]}.sql" | |
filename = "#{Rails.root}/#{filename}" unless filename.starts_with?("/") | |
filename | |
end | |
desc "Execute a mysqldump at actual RAILS_ENV database to 'db/dump/database.sql' or the given 'file' parameter" | |
task :export => :environment do | |
db = Rails::Configuration.new.database_configuration[RAILS_ENV] | |
db.symbolize_keys! | |
command = "mysqldump -u#{db[:username]} -p#{db[:password]} #{db[:database]} > #{param_filename}" | |
puts "[DB] Executing commmand: #{command}" | |
system command | |
end | |
desc "Execute a mysql import at actual RAILS_ENV database from 'db/dump/database.sql' or the given 'file' parameter" | |
task :import => :environment do | |
db = Rails::Configuration.new.database_configuration[RAILS_ENV] | |
db.symbolize_keys! | |
command = "mysql -u#{db[:username]} -p#{db[:password]} #{db[:database]} < #{param_filename}" | |
puts "[DB] Executing commmand: #{command}" | |
system command | |
end | |
end | |
desc "Simple alias for rake db:drop && rake db:create && rake db:migrate" | |
task :recreate => :environment do | |
Rake::Task["db:drop"].execute | |
Rake::Task["db:create"].execute | |
Rake::Task["db:migrate"].execute | |
end | |
end |
This file contains 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
require 'rake/testtask' | |
Rake::TestTask.new(:test) do |test| | |
test.test_files = FileList.new('test/**/test_*.rb') do |list| | |
list.exclude 'test/test_helper.rb' | |
end | |
test.libs << 'test' | |
test.verbose = true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment