Permalink
Browse files

Refactor check for local databases (closes #10539) [parcelbrat]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8535 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 424c330 commit 64b4c18e159a1a75f70b64c5be780eb5cfe92aa9 @dhh dhh committed Jan 3, 2008
Showing with 12 additions and 11 deletions.
  1. +12 −11 railties/lib/tasks/databases.rake
@@ -16,11 +16,7 @@ namespace :db do
# <<: *defaults
next unless config['database']
# Only connect to local databases
- if %w( 127.0.0.1 localhost ).include?(config['host']) || config['host'].blank?
- create_database(config)
- else
- p "This task only creates local databases. #{config['database']} is on a remote host."
- end
+ local_database?(config) { create_database(config) }
end
end
end
@@ -65,11 +61,7 @@ namespace :db do
# Skip entries that don't have a database key
next unless config['database']
# Only connect to local databases
- if config['host'] == 'localhost' || config['host'].blank?
- drop_database(config)
- else
- p "This task only drops local databases. #{config['database']} is on a remote host."
- end
+ local_database?(config) { drop_database(config) }
end
end
end
@@ -79,6 +71,15 @@ namespace :db do
drop_database(ActiveRecord::Base.configurations[RAILS_ENV || 'development'])
end
+ def local_database?(config, &block)
+ if %w( 127.0.0.1 localhost ).include?(config['host']) || config['host'].blank?
+ yield
+ else
+ puts "This task only modifies local databases. #{config['database']} is on a remote host."
+ end
+ end
+
+
desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x. Turn off output with VERBOSE=false."
task :migrate => :environment do
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
@@ -358,4 +359,4 @@ end
def firebird_db_string(config)
FireRuby::Database.db_string_for(config.symbolize_keys)
-end
+end

0 comments on commit 64b4c18

Please sign in to comment.