Its all about Ruby On Rails
Posts tagged sake
Tip: Open DB shell/console from rails root dir
Jan 29th
Just a quick tip you might be using this already.
If you guys want to open your app’s DB shell. Then you can use rails utility ‘dbconsole’ by issuing “script/dbconsole” from rails root directory.
It will ask for DB password, and open your db shell.
If you use sake, you may like following sake task:
desc 'Launches the database shell using the values defined in config/database.yml' task 'db:shell', :needs => [ 'environment' ] do config = ActiveRecord::Base.configurations[(RAILS_ENV or "development")] command = "" case config["adapter"] when "mysql" then (command << "mysql ") (command << "--host=#{(config["host"] or "localhost")} ") (command << "--port=#{(config["port"] or 3306)} ") (command << "--user=#{(config["username"] or "root")} ") (command << "--password=#{(config["password"] or "")} ") (command << config["database"]) when "postgresql" then puts("You should consider switching to MySQL or get off your butt and submit a patch") else (command << "echo Unsupported database adapter: #{config["adapter"]}") end system(command) end