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

Fix `transaction` reverting for migrations #31604

Merged
merged 1 commit into from Sep 27, 2018

Conversation

Projects
None yet
4 participants
@fatkodima
Contributor

fatkodima commented Dec 31, 2017

Commands than run inside a transaction block in a reverted migration ran uninverted, as is.
So, e.g. reverting this a bit contrived migration will fail:

class CreateComments < ActiveRecord::Migration[5.2]
  def change
    transaction do
      create_table :posts do |t|
        t.string :title
        t.text :body

        t.timestamps
      end
    end
  end
end

But, intuitively, it should be reverted and table should be removed.

This change fixes that problems with uninverted transaction blocks.

Originates from outdated #22141 and addresses only new migrations.

@rails-bot

This comment has been minimized.

Show comment
Hide comment
@rails-bot

rails-bot Dec 31, 2017

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @eileencodes (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

rails-bot commented Dec 31, 2017

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @eileencodes (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

Show outdated Hide outdated activerecord/CHANGELOG.md Outdated
@fatkodima

This comment has been minimized.

Show comment
Hide comment
@fatkodima

fatkodima Jan 15, 2018

Contributor

@eileencodes thank you for review. Fixed your notes.
Is there anything that I should do?

Contributor

fatkodima commented Jan 15, 2018

@eileencodes thank you for review. Fixed your notes.
Is there anything that I should do?

@gmcgibbon

Still relevant in Rails 6 (0a4c2d4). Please rebase and move your compatibility changes to V5_2.

@@ -108,11 +108,17 @@ def change_table(table_name, options = {}) # :nodoc:
yield delegate.update_table_definition(table_name, self)
end
def replay(migration)
commands.each do |cmd, args, block|
migration.send(cmd, *args, &block)

This comment has been minimized.

@gmcgibbon

gmcgibbon Sep 26, 2018

Member

Are we able to use #public_send here?

@gmcgibbon

gmcgibbon Sep 26, 2018

Member

Are we able to use #public_send here?

This comment has been minimized.

@fatkodima

fatkodima Sep 26, 2018

Contributor

Unfortunately, no. For example, this method

is private.

@fatkodima

fatkodima Sep 26, 2018

Contributor

Unfortunately, no. For example, this method

is private.

@@ -16,6 +16,12 @@ def self.find(version)
V5_2 = Current
class V5_1 < V5_2
module CommandRecorder

This comment has been minimized.

@gmcgibbon

gmcgibbon Sep 26, 2018

Member

You should move these changes to the V5_2 class now that V6_0 is current.

@gmcgibbon

gmcgibbon Sep 26, 2018

Member

You should move these changes to the V5_2 class now that V6_0 is current.

This comment has been minimized.

@fatkodima

fatkodima Sep 26, 2018

Contributor

Done.

@fatkodima

fatkodima Sep 26, 2018

Contributor

Done.

Fix `transaction` reverting for migrations
[fatkodima & David Verhasselt]

@eileencodes eileencodes merged commit cb6ea51 into rails:master Sep 27, 2018

2 checks passed

codeclimate All good!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment