-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.ru
66 lines (49 loc) · 1.52 KB
/
config.ru
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# This file is used by Rack-based servers to start the application.
require_relative 'config/environment'
####
# todo/fix: move into dbbrowser gem as utility method - why? why not?
def add_database_url_config()
str = ENV['DATABASE_URL']
if str.blank?
puts "no ENV['DATABASE_URL'] found; skip adding DATABASE_URL config"
return
end
####
# fix/todo:
# for config key (now db)
# use RACK_ENV or RAILS_ENV if present?? why? why not?
# only if not already in config? possible?
db = URI.parse( str )
### use spec instead of config ???
if db.scheme == 'postgres'
config = {
adapter: 'postgresql',
host: db.host,
port: db.port,
username: db.user,
password: db.password,
database: db.path[1..-1],
encoding: 'utf8'
}
else
config = {
adapter: db.scheme, # sqlite3
database: db.path[1..-1] # pluto.db (NB: cut off leading /, thus 1..-1)
}
end
puts 'db settings:'
pp config
if ActiveRecord::Base.configurations.nil?
puts "ActiveRecord configurations nil - set to empty hash"
ActiveRecord::Base.configurations = {} # make it an empty hash
end
puts 'ar configurations (before):'
pp ActiveRecord::Base.configurations
ActiveRecord::Base.configurations['db'] = config
puts 'ar configurations (after):'
pp ActiveRecord::Base.configurations
end
add_database_url_config()
run Sportdbhost::Application
## use generic application - why? why not?
## run Rails.application