Question

How do I get a dump of the SQL that my rails migration is attempting to execute?

I've tried using mysql profiler

MySQL Console: set profiling=1;

Rails Console: require 'path/to/my_data_migration.rb' MyDataMigration.down

MySQL Console: show profiles; This returns me back: Empty set (0.00 sec)

Environment: Rails 3.2.17

DB: MySQL 5.5.28

If this functionality isn't baked into ruby/rails/mysql I'd be interested in learning about a tools that can dump the profiled SQL to the command line.

Was it helpful?

Solution

I found one answer here from DZone snippets.

In rails console: ActiveRecord::Base.logger = Logger.new(STDOUT) ActiveRecord::Base.clear_active_connections!

One thing that makes this not the most ideal answer is that if you need to do a hard reload of the rails console (not reload!), then you will have to punch these lines in again. It would be nice if there was a way to keep the profiling running in a background process.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top