Okay, so say we have a database on our production/qa server that we want to test a coding change against.
What i’d usually do would be to:
svn commit
rake deploy
That’s not really good practice for working in a team, as we don’t want to check in cruft that someone might pick up…. or kill the production server!
Alternatives
- Mirroring data from our remote database to our local copy
- Connect directly to the remote database
Obviously i’m focusing on the second one for now, but i might take a look into the other at some point…. :)
Because of our secure setup, we can’t just connect directly to the database from outside. So….
Enter the tunnel
What we want to do is create a tunnel from our development machine to the remote database. Fire open the command line. I’m assuming you’re using mysql, and it’s on port 3306… just choose a random ephemeral port for the local port.
ssh dave@server.domain.com -L 10293:127.0.0.1:3306
What we’re doing is routing traffic via ssh, through port 10293 on our local machine to mysql on our remote server. If you were successful, a new shell should open to the remote server.
What’s the connection
We can connect to the database by any means we want now, I like to use cocoamysql for browsing, the following snippet from datebase.yml should help configure things,
production:
adapter: mysql
database: database_name
username: dave
password: xxxxxxx
host: server.domain.com
port: 10293