Created
November 13, 2008 19:21
-
-
Save kaichen/24572 to your computer and use it in GitHub Desktop.
test db prepare for merb
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
namespace :db do | |
namespace :test do | |
desc "Create the test DB and do migrations automatonlly" | |
task :prepare do | |
Merb.start_environment(:environment => 'test', :adapter => 'runner') | |
config = Merb::Orms::DataMapper.config | |
puts "Creating database '#{config[:database]}'" | |
case config[:adapter] | |
when 'postgres' | |
`createdb -U #{config[:username]} #{config[:database]}` | |
when 'mysql' | |
`mysqladmin -u #{config[:username]} #{config[:password] ? "-p'#{config[:password]}'" : ''} create #{config[:database]}` | |
when 'sqlite3' | |
Rake::Task['rake:db:automigrate'].invoke | |
else | |
raise "Adapter #{config[:adapter]} not supported for creating databases yet." | |
end | |
::DataMapper::AutoMigrator.auto_migrate | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment