Skip to content

Commit 93ee268

Browse files
committed
Preserve up and down return type
In Rails 4.2 calling `ActiveRecord::Migrator.migrate` would return an array of results. Without realizing that this return type was expected I accidentally introduced a change in rails@4d60e93 This PR preserves the previous behavior and adds a test on the return type. This will need a backport to 5.0 branch.
1 parent 98c6e4e commit 93ee268

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

activerecord/lib/active_record/migration.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,9 +1170,10 @@ def load_migrated
11701170
def run_without_lock
11711171
migration = migrations.detect { |m| m.version == @target_version }
11721172
raise UnknownMigrationVersionError.new(@target_version) if migration.nil?
1173-
execute_migration_in_transaction(migration, @direction)
1173+
result = execute_migration_in_transaction(migration, @direction)
11741174

11751175
record_environment
1176+
result
11761177
end
11771178

11781179
# Used for running multiple migrations up to or down to a certain value.
@@ -1181,11 +1182,12 @@ def migrate_without_lock
11811182
raise UnknownMigrationVersionError.new(@target_version)
11821183
end
11831184

1184-
runnable.each do |migration|
1185+
result = runnable.each do |migration|
11851186
execute_migration_in_transaction(migration, @direction)
11861187
end
11871188

11881189
record_environment
1190+
result
11891191
end
11901192

11911193
# Stores the current environment in the database.

activerecord/test/cases/migrator_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,20 @@ def test_migrator_going_down_due_to_version_target
290290
assert_equal [[:up, 1], [:up, 2], [:up, 3]], calls
291291
end
292292

293+
def test_migrator_output
294+
_, migrator = migrator_class(3)
295+
296+
result = migrator.migrate("valid")
297+
assert_equal(3, result.count)
298+
299+
# Nothing migrated from duplicate run
300+
result = migrator.migrate("valid")
301+
assert_equal(0, result.count)
302+
303+
result = migrator.rollback("valid")
304+
assert_equal(1, result.count)
305+
end
306+
293307
def test_migrator_rollback
294308
_, migrator = migrator_class(3)
295309

0 commit comments

Comments
 (0)