aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/commands/dbconsole.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails/commands/dbconsole.rb')
-rw-r--r--railties/lib/rails/commands/dbconsole.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/railties/lib/rails/commands/dbconsole.rb b/railties/lib/rails/commands/dbconsole.rb
index 77c3404343..593e2d8ee3 100644
--- a/railties/lib/rails/commands/dbconsole.rb
+++ b/railties/lib/rails/commands/dbconsole.rb
@@ -34,9 +34,8 @@ module Rails
abort opt.to_s unless (0..1).include?(ARGV.size)
end
- env = ARGV.first || ENV['RAILS_ENV'] || 'development'
- unless config = YAML::load(ERB.new(IO.read("#{@app.root}/config/database.yml")).result)[env]
- abort "No database is configured for the environment '#{env}'"
+ unless config = YAML::load(ERB.new(IO.read("#{@app.root}/config/database.yml")).result)[Rails.env]
+ abort "No database is configured for the environment '#{Rails.env}'"
end
@@ -97,4 +96,9 @@ module Rails
end
end
end
+end
+
+# Has to set the RAILS_ENV before config/application is required
+if ARGV.first && !ARGV.first.index("-") && env = ARGV.first
+ ENV['RAILS_ENV'] = %w(production development test).find { |e| e.index(env) } || env
end \ No newline at end of file