Skip to content

Commit 85d815d

Browse files
committed
verified that DATABASE_URL now works as expected (even with JDBC props)
e.g. `rake db:version DATABASE_URL="mysql://localhost/rails32?prepared_statements=true&cachePrepStmts=true&cacheResultSetMetadata=true&profileSQL=true"`
1 parent 1cda6bb commit 85d815d

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

lib/arjdbc/tasks/databases.rake

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
raise "ArJdbc needs rake 0.9.x or newer" unless Rake.const_defined?(:VERSION)
22

33
Rake::DSL.module_eval do
4-
4+
55
def redefine_task(*args, &block)
66
if Hash === args.first
77
task_name = args.first.keys[0]
@@ -10,9 +10,9 @@ Rake::DSL.module_eval do
1010
task_name = args.first; old_prereqs = []
1111
# args[0] = { task_name => old_prereqs }
1212
end
13-
13+
1414
full_name = Rake::Task.scope_name(Rake.application.current_scope, task_name)
15-
15+
1616
if old_task = Rake.application.lookup(task_name)
1717
old_comment = old_task.full_comment
1818
old_prereqs = old_task.prerequisites.dup if old_prereqs
@@ -25,59 +25,57 @@ Rake::DSL.module_eval do
2525
else
2626
# raise "could not find rake task with (full) name '#{full_name}'"
2727
end
28-
28+
2929
new_task = task(*args, &block)
3030
new_task.comment = old_comment # if old_comment
3131
new_task.actions.concat(old_actions) if old_actions
3232
new_task.prerequisites.concat(old_prereqs) if old_prereqs
3333
new_task
3434
end
35-
35+
3636
end
3737

3838
namespace :db do
3939

4040
def rails_env
4141
defined?(Rails.env) ? Rails.env : ( RAILS_ENV || 'development' )
4242
end
43-
43+
4444
def adapt_jdbc_config(config)
4545
return config unless config['adapter']
4646
config.merge 'adapter' => config['adapter'].sub(/^jdbc/, '')
4747
end
48-
48+
4949
if defined? ActiveRecord::Tasks::DatabaseTasks # 4.0
50-
50+
5151
def current_config(options = {})
5252
ActiveRecord::Tasks::DatabaseTasks.current_config(options)
5353
end
54-
54+
5555
else # 3.x / 2.3
56-
56+
5757
def current_config(options = {}) # not on 2.3
5858
options = { :env => rails_env }.merge! options
5959
if options[:config]
6060
@current_config = options[:config]
6161
else
62-
@current_config ||=
63-
if ENV['DATABASE_URL']
64-
database_url_config
65-
else
66-
ActiveRecord::Base.configurations[options[:env]]
67-
end
62+
@current_config ||= ENV['DATABASE_URL'] ?
63+
database_url_config : ActiveRecord::Base.configurations[options[:env]]
6864
end
6965
end
7066

7167
def database_url_config(url = ENV['DATABASE_URL'])
68+
# NOTE: ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver
69+
# since AR 4.0 that is handled by DatabaseTasks - only care about 2.3/3.x :
7270
unless defined? ActiveRecord::Base::ConnectionSpecification::Resolver
73-
raise "ENV['DATABASE_URL'] not support on AR #{ActiveRecord::VERSION::STRING}"
71+
raise "DATABASE_URL not supported on ActiveRecord #{ActiveRecord::VERSION::STRING}"
7472
end
75-
@database_url_config ||=
76-
ActiveRecord::Base::ConnectionSpecification::Resolver.new(url, {}).spec.config.stringify_keys
73+
resolver = ActiveRecord::Base::ConnectionSpecification::Resolver.new(url, {})
74+
resolver.spec.config.stringify_keys
7775
end
78-
76+
7977
end
80-
78+
8179
end
8280

8381
require 'arjdbc/tasks/database_tasks'

0 commit comments

Comments
 (0)