rails/rails — pull request #13355 by dylanahsmith (2013-12-17 21:49:49+00:00)
Title: activerecord: Initialize Migration with version from MigrationProxy.

## Problem

When running migrations with `rake db:migrate`, notice how the output to standard output looks like the following.

```
== CreateUserTable: migrating ================================================
== CreateUserTable: migrated (0.0000s) =======================================
```

This output is done through Migration#announce, delegated from MigrationProxy, as follows

From
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/migration.rb#L596
```ruby
def announce(message)
text = "#{version} #{name}: #{message}"
length = [0, 75 - text.length].max
write "== %s %s" % [text, "=" * length]
end
```

The output is supposed to include a version, but the version is always `nil` within the migration. The MigrationProxy has the version, but initializes the Migration with the default parameters (i.e. `version = nil`)

This missing version can also be a problem when trying to use the version within a migration. Our use case for doing this is to update a schema_migrations table on each shard, so a migration that succeeds on one shard, then fails on another, can be retried only on the shards it still needs to run on.

## Solution

Initialize the Migration loaded from a MigrationProxy with the version.

## Backport

This can be cherry-picked without conflict onto the 4-0-stable or 3-2-stable branch.