-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdb
More file actions
executable file
·25 lines (21 loc) · 755 Bytes
/
db
File metadata and controls
executable file
·25 lines (21 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env ruby
require 'yaml'
# quickly access sql databases
# (only works for rails apps right now)
# assumes dev environment, and mysql, will generalize later
dbfile = 'config/database.yml'
if File.exist?(dbfile)
config = YAML::load(File.open(dbfile, 'r').read)
dbdata = config['development']
dbhost = dbdata['host']
dbpasswd = (dbdata['password'] == nil) ? "" : " -p#{dbdata['password']} "
argcmd = ARGV.join(' ')
dbcmd = if dbdata['adapter'] =~ /mysql/
"mysql -D#{dbdata['database']} -h#{dbhost} -u#{dbdata['username']} #{dbpasswd} -e '#{argcmd}'"
else
"psql -A --pset footer -d #{dbdata['database']} -c '#{argcmd}'"
end
system(dbcmd) unless ( argcmd =~ /(drop|delete)/i )
else
puts "Not in rails app"
end