Skip to content

Instantly share code, notes, and snippets.

@corny
Created June 1, 2012 11:16
Show Gist options
  • Save corny/2851323 to your computer and use it in GitHub Desktop.
Save corny/2851323 to your computer and use it in GitHub Desktop.
Hot fix that adds support for dumping triggers to the mysql2 adapter.
# config/initializers/mysql2_dump_triggers.rb
module TriggerDumper
def structure_dump
super << select_all("SHOW TRIGGERS").map { |trigger|
exec_without_stmt("SHOW CREATE TRIGGER #{trigger['Trigger']}").first['SQL Original Statement'].sub(/DEFINER=\S+ /,'') << "\n\n"
}.join
end
end
ActiveRecord::ConnectionAdapters::Mysql2Adapter.send :include, TriggerDumper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment