diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2012-05-06 16:23:38 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2012-05-06 16:23:38 -0700 |
commit | b41bfb04b9e3e88b22f0d78c5f06c8cb44c5ae0a (patch) | |
tree | 18d4c640b968080353399c67546c92cceac4fbe8 /railties/lib | |
parent | a29bc1cf7b8580a815523e4c3a79e931f03ab8c2 (diff) | |
parent | 346bb018499cde6699fcce6c68dd7e9be45c75e1 (diff) | |
download | rails-b41bfb04b9e3e88b22f0d78c5f06c8cb44c5ae0a.tar.gz rails-b41bfb04b9e3e88b22f0d78c5f06c8cb44c5ae0a.tar.bz2 rails-b41bfb04b9e3e88b22f0d78c5f06c8cb44c5ae0a.zip |
Merge pull request #5910 from route/rails-dbconsole
Fast path starts the database console without loading the full Rails env
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/commands.rb | 3 | ||||
-rw-r--r-- | railties/lib/rails/commands/dbconsole.rb | 38 |
2 files changed, 29 insertions, 12 deletions
diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb index 82cdd6053b..7f473c237c 100644 --- a/railties/lib/rails/commands.rb +++ b/railties/lib/rails/commands.rb @@ -57,8 +57,7 @@ when 'server' when 'dbconsole' require 'rails/commands/dbconsole' - require APP_PATH - Rails::DBConsole.start(Rails.application) + Rails::DBConsole.start when 'application', 'runner' require "rails/commands/#{command}" diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb index 25a8caeec3..aaba47117f 100644 --- a/railties/lib/rails/commands/dbconsole.rb +++ b/railties/lib/rails/commands/dbconsole.rb @@ -5,15 +5,37 @@ require 'rbconfig' module Rails class DBConsole - attr_reader :arguments + attr_reader :arguments, :config - def self.start(app) - new(app).start + def self.start + new(config).start end - def initialize(app, arguments = ARGV) - @app = app - @arguments = arguments + def self.config + config = begin + YAML.load(ERB.new(IO.read("config/database.yml")).result) + rescue SyntaxError, StandardError + require APP_PATH + Rails.application.config.database_configuration + end + + unless config[env] + abort "No database is configured for the environment '#{env}'" + end + + config[env] + end + + def self.env + if Rails.respond_to?(:env) + Rails.env + else + ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development" + end + end + + def initialize(config, arguments = ARGV) + @config, @arguments = config, arguments end def start @@ -38,10 +60,6 @@ module Rails abort opt.to_s unless (0..1).include?(arguments.size) end - unless config = @app.config.database_configuration[Rails.env] - abort "No database is configured for the environment '#{Rails.env}'" - end - case config["adapter"] when /^mysql/ |