Skip to content

Instantly share code, notes, and snippets.

@stuartc
Created May 23, 2013 18:36
Show Gist options
  • Save stuartc/5638370 to your computer and use it in GitHub Desktop.
Save stuartc/5638370 to your computer and use it in GitHub Desktop.
WIP on forcing AR Migrations to not use transactions.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment