Guest User

Untitled

a guest
Apr 26th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require 'pathname'
  4. require 'yaml'
  5.  
  6. conf = Pathname.new(Dir.pwd).join('config', 'database.yml')
  7.  
  8. if conf.exist?
  9. env = ARGV.first || ENV['RAILS_ENV'] || 'development'
  10. yaml = YAML.load(conf.read)
  11. config = yaml[env] || yaml[env.to_sym]
  12. database = config['database'] || config[:database]
  13. username = config['username'] || config[:username]
  14. password = config['password'] || config[:password]
  15. cmd = "mysql -u#{username} "
  16. cmd << "-p#{password} " if password
  17. cmd << database
  18. puts "Opening database #{database}"
  19. exec cmd
  20. end
  21.  
  22. puts "Couldn't detect database"
  23. exit 1
Add Comment
Please, Sign In to add comment