Created
April 15, 2014 12:06
-
-
Save ILoGM/10726943 to your computer and use it in GitHub Desktop.
This patch allows disable ddl transactions in Rails 3.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActiveRecord::Migrator | |
def migrate(&block) | |
current = migrations.detect { |m| m.version == current_version } | |
target = migrations.detect { |m| m.version == @target_version } | |
if target.nil? && @target_version && @target_version > 0 | |
raise UnknownMigrationVersionError.new(@target_version) | |
end | |
start = up? ? 0 : (migrations.index(current) || 0) | |
finish = migrations.index(target) || migrations.size - 1 | |
runnable = migrations[start..finish] | |
# skip the last migration if we're headed down, but not ALL the way down | |
runnable.pop if down? && target | |
ran = [] | |
runnable.each do |migration| | |
if block && !block.call(migration) | |
next | |
end | |
ActiveRecord::Base.logger.info "Migrating to #{migration.name} (#{migration.version})" if ActiveRecord::Base.logger | |
seen = migrated.include?(migration.version.to_i) | |
# On our way up, we skip migrating the ones we've already migrated | |
next if up? && seen | |
# On our way down, we skip reverting the ones we've never migrated | |
if down? && !seen | |
migration.announce 'never migrated, skipping'; migration.write | |
next | |
end | |
begin | |
migrate = Proc.new do | |
migration.migrate(@direction) | |
record_version_state_after_migrating(migration.version) | |
end | |
if Settings.migrations_without_transaction.include?(migration.name) | |
migrate.call | |
else | |
ddl_transaction do | |
migrate.call | |
end | |
end | |
ran << migration | |
rescue => e | |
canceled_msg = ActiveRecord::Base.connection.supports_ddl_transactions? ? "this and " : "" | |
raise StandardError, "An error has occurred, #{canceled_msg}all later migrations canceled:\n\n#{e}", e.backtrace | |
end | |
ran | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment