-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
activerecord: Initialize Migration with version from MigrationProxy. #13355
Conversation
Any way to provide a test case so that we can be safe it won't happen again in the future? Thanks for the detailed explanation. |
The migration itself is not exposed on the MigrationProxy, so I just created a migration that raised if the version was incorrect as a test. |
@@ -79,6 +79,12 @@ def test_migrator_versions | |||
ActiveRecord::Migrator.migrations_paths = old_path | |||
end | |||
|
|||
def test_migration_version | |||
assert_nothing_raised do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the assert_nothing_raised
. If something is raised the test will fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the assert_nothing_raised
❤️ 💚 💜 💛 |
@dylanahsmith Can you add a changelog for this? |
👍 |
Superb. 👍 |
Added an active record changelog entry. |
activerecord: Initialize Migration with version from MigrationProxy. Conflicts: activerecord/CHANGELOG.md
activerecord: Initialize Migration with version from MigrationProxy. Conflicts: activerecord/CHANGELOG.md Conflicts: activerecord/CHANGELOG.md
Problem
When running migrations with
rake db:migrate
, notice how the output to standard output looks like the following.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
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.