Permalink
Browse files

allow creating and deleting specific databases

  • Loading branch information...
1 parent f8a5981 commit c24e352639a1e71ddead42abbe2ca07341f84c11 dave farkas committed with Arnaud Berthomier Jul 8, 2009
Showing with 19 additions and 8 deletions.
  1. +13 −4 lib/couch_rest_rails/database.rb
  2. +6 −4 tasks/couch_rest_rails_tasks.rake
@@ -3,11 +3,16 @@ module Database
extend self
- def create
+ def create(database)
+ return "Database '#{database}' doesn't exists" unless
+ (database == "*" || File.exist?(File.join(RAILS_ROOT,
+ CouchRestRails.setup_path,
+ database)))
+
# get list of available_databases in couch...
existing_databases = COUCHDB_SERVER.databases
# get all the model files
- Dir[File.join(RAILS_ROOT, CouchRestRails.setup_path,'*')].each do |db|
+ Dir[File.join(RAILS_ROOT, CouchRestRails.setup_path,database)].each do |db|
# check for a directory...
if File::directory?( db )
database_name =COUCHDB_CONFIG[:db_prefix] + File.basename(db) +
@@ -28,11 +33,15 @@ def create
"create complete"
end
- def delete
+ def delete(database)
+ return "Database '#{database}' doesn't exists" unless
+ (database == "*" || File.exist?(File.join(RAILS_ROOT,
+ CouchRestRails.setup_path,
+ database)))
# get list of available_databases in couch...
existing_databases = COUCHDB_SERVER.databases
# get all the model files
- Dir[File.join(RAILS_ROOT, CouchRestRails.setup_path,"*")].each do |db|
+ Dir[File.join(RAILS_ROOT, CouchRestRails.setup_path,database)].each do |db|
# check for a directory...
if File::directory?( db )
database_name =COUCHDB_CONFIG[:db_prefix] + File.basename(db) +
@@ -1,13 +1,15 @@
namespace :couchdb do
desc "Create the CouchDB database defined in config/couchdb.yml for the current environment"
- task :create => :environment do
- puts CouchRestRails::Database.create
+ task :create, :database, :needs => :environment do |t, args|
+ args.with_defaults(:database => "*")
+ puts CouchRestRails::Database.create(args.database)
end
desc "Deletes the CouchDB database for the current RAILS_ENV"
- task :delete => :environment do
- puts CouchRestRails::Database.delete
+ task :delete, :database, :needs => :environment do |t, args|
+ args.with_defaults(:database => "*")
+ puts CouchRestRails::Database.delete(args.database)
end
desc "Deletes and recreates the CouchDB database for the current RAILS_ENV"

0 comments on commit c24e352

Please sign in to comment.