mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Refactor check for local databases (closes #10539) [parcelbrat]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8535 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
424c330634
commit
64b4c18e15
1 changed files with 12 additions and 11 deletions
|
@ -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
|
Loading…
Reference in a new issue