views:

112

answers:

2

Is there an easy way to see the actual SQL generated by a rails migration?

I have a situation where a migration to change a column type worked on my local development machine by partially failed on the production server.

My postgreSQL versions are different between local and production (7 on production, 8 on local) so I'm hoping by looking at the SQL generated on the successful migration locally I can work out a SQL statement to run on production to fix things....

+2  A: 

Look at the log files: log/development.log locally vs log/production.log on your server.

François Beausoleil
Thanks Francois! Your suggestion worked fine but I had some trouble as my logfile was HUGE and a bit hard to parse... However, you reminded me of something I'd read a while ago about PostgreSQL's own logfile and I ended up finding a solution that did what I was looking for. +1
Ganesh Shankar
A: 

I did some digging and found another way this can be achieved too... (This way only gives you the SQL so it was a bit easier for me to read)

Postgresql will log all the queries executed if you put this line in your config file: (there's an example which has been commented out in the "What to log" section of the config file)

log_statement = 'all'

Then I rolled back and re-ran my migration locally to find the SQL I was looking for.

This method also gives you the SQL in a format where you can easily paste it into something like PGAdmin's query builder and mess around with it.

Ganesh Shankar