Permalink
Browse files

Added sequel:db:drop and sequel:db:create tasks

  • Loading branch information...
1 parent 4f7605b commit 64f0abc06917d26aec5cb6e496fc912e8d097fc2 @pk pk committed Feb 17, 2009
Showing with 31 additions and 0 deletions.
  1. +31 −0 merb_sequel/lib/merb_sequel/merbtasks.rb
@@ -20,6 +20,37 @@
Sequel::Migrator.apply(Sequel::Model.db, "schema/migrations", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
end
+ desc "Create the database according to the config from the database.yaml. Use [username,password] if you need another user to connect to DB than in config."
+ task :create, :username, :password do |t,args|
+ config = Merb::Orms::Sequel.config
+ puts "Creating database '#{config[:database]}'"
+ case config[:adapter]
+ when 'postgres'
+ if args.username.nil?
+ `createdb -U #{config[:username]} #{config[:database]}`
+ else
+ `createdb -U #{args.username} -O #{config[:username]} #{config[:database]}`
+ end
+ when 'mysql'
+ `mysqladmin -u #{config[:username]} #{config[:password] ? "-p'#{config[:password]}'" : ''} create #{config[:database]}`
+ else
+ raise "Adapter #{config[:adapter]} not supported for creating databases yet."
+ end
+ end
+
+ desc "Drop the database for enviroment from database.yaml (postgres only). Use [username,password] if you need another user to connect to DB than in config."
+ task :drop, :username, :password do |t,args|
+ config = Merb::Orms::Sequel.config
+ user = args.username.nil? ? config[:username]: args.username
+ puts "Droping database '#{config[:database]}'"
+ case config[:adapter]
+ when 'postgres'
+ `dropdb -U #{user} #{config[:database]}`
+ else
+ raise "Adapter #{config[:adapter]} not supported for dropping databases yet."
+ end
+ end
+
desc "Truncate all tables in database"
task :truncate => :sequel_env do
db = Sequel::Model.db

0 comments on commit 64f0abc

Please sign in to comment.