don't check for rails, just check for if defined?(ActiveRecord::Migration::CommandRecorder)
You didn't escape the regex, so any prefix with regex magick characters would have thrown this off.
When you call add_foreign_key with a symbol in a schema migration, you'll actually get the wrapped table name (but that's not how this is tested, so it needs to work in both fashions)