module NoTransactionBlock module Nothing def nothing puts "CALLED" end end module MigrationHelpers def without_transaction_block(&block) ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:include,Nothing) ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.class_eval do alias_method :orig_begin_db_transaction, :begin_db_transaction alias_method :orig_commit_db_transaction, :commit_db_transaction alias_method :orig_rollback_db_transaction, :rollback_db_transaction alias_method :begin_db_transaction, :nothing alias_method :commit_db_transaction, :nothing alias_method :rollback_db_transaction, :nothing end block.call end end def self.included(base) base.extend MigrationHelpers end end include NoTransactionBlock