Created
July 21, 2009 18:50
-
-
Save brianmario/151513 to your computer and use it in GitHub Desktop.
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
# Override the default db:drop and db:create Rake tasks to fix bug with using a database driver | |
# other than mysql, postgres or sqlite. | |
namespace :db do | |
task :create do | |
@charset = ENV['CHARSET'] || 'utf8' | |
@collation = ENV['COLLATION'] || 'utf8_general_ci' | |
config = ActiveRecord::Base.configurations[RAILS_ENV || 'development'] | |
begin | |
ActiveRecord::Base.establish_connection(config.merge('database' => nil)) | |
ActiveRecord::Base.connection.create_database(config['database'], :charset => (config['charset'] || @charset), :collation => (config['collation'] || @collation)) | |
ActiveRecord::Base.establish_connection(config) | |
rescue Exception => e | |
puts "#{config['database']} already exists" | |
end | |
end | |
task :drop do | |
config = ActiveRecord::Base.configurations[RAILS_ENV || 'development'] | |
begin | |
ActiveRecord::Base.establish_connection(config) | |
ActiveRecord::Base.connection.drop_database config['database'] | |
rescue Exception => e | |
puts "Couldn't drop #{config['database']} : #{e.inspect}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment