Skip to content

Instantly share code, notes, and snippets.

@rogerleite
Created September 12, 2010 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogerleite/576584 to your computer and use it in GitHub Desktop.
Save rogerleite/576584 to your computer and use it in GitHub Desktop.
rake functions
# 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
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