How to view Rails Migration output

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

I had a situation where the migration to change the type of column worked on my local development machine, partially failing on the production server.

My postgreSQL versions are different between local and production (7 in production, 8 in local), so I hope that by looking at the SQL generated during a successful migration, I can work out an SQL statement to run in production to fix things ....

+6
ruby-on-rails activerecord postgresql migration
source share
3 answers

I searched a bit and found another way that this can be achieved ... (This method gives you only SQL, so it was a little easier for me to read)

Postgresql will record all requests that are executed if you put this line in your configuration file: (there is an example that was commented out in the "What to write" section of the configuration file)

log_statement = 'all' 

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

This method also gives you SQL in a format in which you can easily paste it into something like the PGAdmin query builder and deal with it.

+3
source share

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

+6
source share

You can set the logger to STDOUT at the top of the change , up or down migration methods. Example:

 class SomMigration < ActiveRecord::Migration def change ActiveRecord::Base.logger = Logger.new(STDOUT) # ... end end 

Or see this answer for adding SQL logging to all rake tasks

0
source share

All Articles