Skip to content

Instantly share code, notes, and snippets.

@kaichen
Created November 13, 2008 19:21
Show Gist options
  • Save kaichen/24572 to your computer and use it in GitHub Desktop.
Save kaichen/24572 to your computer and use it in GitHub Desktop.
test db prepare for merb
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