Skip to content
Browse files

Merge pull request #10331 from neerajdotname/exec-migration-in-transa…

…ction

Remove code duplication
  • Loading branch information...
2 parents 0d8a100 + 44ea48e commit 4e7fa91332ea08aa29e69e905413abba78d93d78 @guilleiguaran guilleiguaran committed Apr 24, 2013
Showing with 9 additions and 8 deletions.
  1. +9 −8 activerecord/lib/active_record/migration.rb
View
17 activerecord/lib/active_record/migration.rb
@@ -871,10 +871,7 @@ def run
raise UnknownMigrationVersionError.new(@target_version) if migration.nil?
unless (up? && migrated.include?(migration.version.to_i)) || (down? && !migrated.include?(migration.version.to_i))
begin
- ddl_transaction(migration) do
- migration.migrate(@direction)
- record_version_state_after_migrating(migration.version)
- end
+ execute_migration_in_transaction(migration, @direction)
rescue => e
canceled_msg = use_transaction?(migration) ? ", this migration was canceled" : ""
raise StandardError, "An error has occurred#{canceled_msg}:\n\n#{e}", e.backtrace
@@ -899,10 +896,7 @@ def migrate
Base.logger.info "Migrating to #{migration.name} (#{migration.version})" if Base.logger
begin
- ddl_transaction(migration) do
- migration.migrate(@direction)
- record_version_state_after_migrating(migration.version)
- end
+ execute_migration_in_transaction(migration, @direction)
rescue => e
canceled_msg = use_transaction?(migration) ? "this and " : ""
raise StandardError, "An error has occurred, #{canceled_msg}all later migrations canceled:\n\n#{e}", e.backtrace
@@ -939,6 +933,13 @@ def ran?(migration)
migrated.include?(migration.version.to_i)
end
+ def execute_migration_in_transaction(migration, direction)
+ ddl_transaction(migration) do
+ migration.migrate(direction)
+ record_version_state_after_migrating(migration.version)
+ end
+ end
+
def target
migrations.detect { |m| m.version == @target_version }
end

0 comments on commit 4e7fa91

Please sign in to comment.
Something went wrong with that request. Please try again.