This project is archived and is in readonly mode.
[PATCH] Add "script/dbconsole"
-
alpinegizmo
This is one of those great little improvements that makes sense instantly, and you use several times a day. It's especially sweet when your project has lots of environments.
-
Gravis
nice one. +1
-
Ben Nolan
I use this regularly. If it's a small patch I'd love having it in core.
-
Jeremy Kemper
I'd use a script instead of a rake task. Here's the script/mysql I add to most apps:
#!/usr/bin/env ruby require 'yaml' configs = YAML.load_file("#{File.dirname(__FILE__)}/../config/database.yml") rails_env = ARGV.shift || ENV['RAILS_ENV'] || 'development' unless configs.include?(rails_env) abort "Missing database.yml config for #{rails_env.inspect} environment." end db = configs[rails_env] command = "mysql #{db['database']}" { 'host' => '--host', 'port' => '--port', 'socket' => '--socket', 'username' => '--user', 'password' => '--password' }.each do |key, opt| if value = db[key] command << " #{opt}=#{value}" end end puts "[#{rails_env}] #{command}" exec command -
Steve Purcell
Fair enough. I like the convenience of being able to execute the command from any working directory in my rails project, but nonetheless, here's a patch that adds the functionality as a script instead, using some cues from your script above.
-
Stefan Kaes
+1. I use this all the time.
-
Steve Purcell
- Title changed from Add db:console tasks to [PATCH] Add "script/dbconsole"
-
Jeremy Kemper
Is find_cmd needed? AFAIK Windows doesn't require the .exe suffix and PATH resolution is handled by the shell already.
-
Steve Purcell
Yeah, good question - I think it's needed. Note that it's used both for choosing a preferred binary ("mysql5" vs "mysql") and for handling the .exe thing.
The former case affected me personally (with either MacPorts or Debian; I forget which). The latter (.exe) case surprised me - Stefan Kaes provided a patch for an issue he'd seen. I think he uses Cygwin.
Probably safer to leave find_cmd as-is, but by all means go with what makes the most sense to you.
-
Stefan Kaes
without the .exe magic the correct executable will sometimes not be found on windows. the problem is that some installations add a program.bat file alongside program.exe. invoking the .bat however, will not work.
-
Repository
- State changed from new to resolved
(from [2561732a08ae97fa44706a8eca4db147c4a7c286]) Some dbconsole tweaks. [#102 state:resolved]
-
Steve Purcell
Awesome - thanks Jeremy.
