From 64b4c18e159a1a75f70b64c5be780eb5cfe92aa9 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 3 Jan 2008 00:35:23 +0000 Subject: Refactor check for local databases (closes #10539) [parcelbrat] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8535 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/lib/tasks/databases.rake | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'railties/lib/tasks') diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index 9162be8f30..7d18df1873 100644 --- a/railties/lib/tasks/databases.rake +++ b/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 \ No newline at end of file -- cgit v1.2.3