public this repo is viewable by everyone
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Some dbconsole tweaks. [#102 state:resolved]
jeremy (author)
4 days ago
commit  2561732a08ae97fa44706a8eca4db147c4a7c286
tree    795a3c4e57c5d0cb3a01741e382dfb5c38432097
parent  b510d8bfd8355e63432514814e3177244a26275a
...
 
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
...
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
0
@@ -1,49 +1,55 @@
0
+require 'yaml'
0
 require 'optparse'
0
+
0
 OptionParser.new do |opt|
0
   opt.banner = "Usage: dbconsole [environment]"
0
   opt.parse!(ARGV)
0
   abort opt.to_s unless (0..1).include?(ARGV.size)
0
 end
0
 
0
-env = ENV['RAILS_ENV'] = ARGV.first || ENV['RAILS_ENV'] || 'development'
0
+env = ARGV.first || ENV['RAILS_ENV'] || 'development'
0
+unless config = YAML.load_file(RAILS_ROOT + "/config/database.yml")[env]
0
+ abort "No database is configured for the environment '#{env}'"
0
+end
0
+
0
 
0
 def find_cmd(*commands)
0
- dirs_on_path = ENV['PATH'].split(File::PATH_SEPARATOR)
0
+ dirs_on_path = ENV['PATH'].to_s.split(File::PATH_SEPARATOR)
0
   commands += commands.map{|cmd| "#{cmd}.exe"} if RUBY_PLATFORM =~ /win32/
0
   commands.detect do |cmd|
0
     dirs_on_path.detect do |path|
0
       File.executable? File.join(path, cmd)
0
     end
0
- end || abort("couldn't find matching executable: #{commands.join(', ')}")
0
+ end || abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.")
0
 end
0
 
0
+case config["adapter"]
0
+when "mysql"
0
+ args = {
0
+ 'host' => '--host',
0
+ 'port' => '--port',
0
+ 'socket' => '--socket',
0
+ 'username' => '--user',
0
+ 'password' => '--password',
0
+ 'encoding' => '--default-character-set'
0
+ }.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact
0
 
0
-require 'yaml'
0
-config = YAML::load(File.read(RAILS_ROOT + "/config/database.yml"))[env]
0
+ args << config['database']
0
 
0
-unless config
0
- abort "No database is configured for the environment '#{env}'"
0
-end
0
+ exec(find_cmd('mysql5', 'mysql'), *args)
0
 
0
-case config["adapter"]
0
-when "mysql"
0
- exec(find_cmd(*%w(mysql5 mysql)),
0
- *({ 'host' => '--host',
0
- 'port' => '--port',
0
- 'socket' => '--socket',
0
- 'username' => '--user',
0
- 'password' => '--password',
0
- 'encoding' => '--default-character-set'
0
- }.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact +
0
- [config['database']]))
0
 when "postgresql"
0
   ENV['PGHOST'] = config["host"] if config["host"]
0
   ENV['PGPORT'] = config["port"].to_s if config["port"]
0
   ENV['PGPASSWORD'] = config["password"].to_s if config["password"]
0
   exec(find_cmd('psql'), '-U', config["username"], config["database"])
0
+
0
 when "sqlite"
0
   exec(find_cmd('sqlite'), config["database"])
0
+
0
 when "sqlite3"
0
   exec(find_cmd('sqlite3'), config["database"])
0
-else abort "not supported for this database type"
0
+
0
+else
0
+ abort "Unknown command-line client for #{config['database']}. Submit a Rails patch to add support!"
0
 end

Comments

    No one has commented yet.