Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make ActiveRecord::Schema.define not log to stdout?

I can't see this in the docs, but I presume it's a solved problem.

I'm using ActiveRecord outside Rails, and my script loads a schema.rb dumped from another app. I want to load this schema without dumping the migration output to stdout, but replacing ActiveRecord::Base.logger doesn't shut it up. What should I be overriding to stop the noise?

like image 973
regularfry Avatar asked Mar 20 '12 12:03

regularfry


1 Answers

The trick is apparently in ActiveRecord::Migration:

ActiveRecord::Migration.verbose = false

This makes migrations not output information to $stdout. There is a convenience wrapper method called .suppress_messages, which you can use like this:

ActiveRecord::Migration.suppress_messages do
  load("path/to/schema.rb")
end

And yes, this is documented under Migration (but not under Schema, where I was looking).

like image 84
regularfry Avatar answered Sep 24 '22 00:09

regularfry