Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 47e95ea

Browse files
committed
Add db:connect rake task
This little task allows for connecting to your local MySQL or Postgres database with `bundle exec rake db:connect`. I've found it useful when trying to inspect the columns of certain tables, for example. Authored-by: Reid Mitchell <rmitchell@pivotal.io>
1 parent b15d26c commit 47e95ea

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

lib/tasks/db.rake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,24 @@ namespace :db do
139139
puts 'Successfully applied latest migrations to CF deployment'
140140
end
141141

142+
desc 'Connect to the database set in spec/support/bootstrap/db_config'
143+
task :connect do
144+
RakeConfig.context = :migrate
145+
146+
require_relative '../../spec/support/bootstrap/db_config'
147+
db_config = DbConfig.new
148+
host, port, user, pass, passenv = parse_db_connection_string
149+
150+
case ENV['DB']
151+
when 'postgres'
152+
sh "#{passenv} psql -q #{host} #{port} #{user} -d #{db_config.name}"
153+
when 'mysql'
154+
sh "mysql #{host} #{port} #{user} #{pass}"
155+
else
156+
puts 'rake db:connect requires DB to be set to connect to a database'
157+
end
158+
end
159+
142160
desc 'Validate Deployments are not missing encryption keys'
143161
task :validate_encryption_keys do
144162
RakeConfig.context = :api

0 commit comments

Comments
 (0)