Skip to content
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 6.1 change_table setting datetime precision [7-0-stable] #49011

Merged
merged 4 commits into from
Aug 23, 2023

Conversation

skipkayhil
Copy link
Member

@skipkayhil skipkayhil commented Aug 23, 2023

This ended up requiring more backports to get fully working:

#46241 - add compatible_table_definition to Current
#47648 - ensure empty options aren't logged
#49012 - move *_table methods up to Current to prevent subclasses not implementing them

Motivation / Background

While working on #48969, I found that some of the Compatibility test cases were not working correctly. The tests removed in this commit were never running the change_table migration and so were not actually testing that change_table works correctly. The issue is that the two migrations created in these tests both have nil versions, and so the Migrator only runs the first one.

Detail

This commit refactors the tests so that its easier to test the behavior of each Migration class version (and I think the rest of the tests should be updated to use this strategy as well). Additionally, since the tests are fixed it exposed that t.change in a change_table is not behaving as expected so that is fixed as well.

Additional information

Ref #48974
(manually backported to 7-0-stable because it did not apply cleanly)

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@skipkayhil
Copy link
Member Author

Hmm, let me fix the test failures

@skipkayhil
Copy link
Member Author

skipkayhil commented Aug 23, 2023

Okay, I believe I've found the issue. compatible_table_definition is not being used for change_table in V6_1 migrations, and was added in d536ffd on main, which is why it's only failing here. Let me open another PR to refactor this because this is easy to miss.

Previously, most version of the Migration class would call `super` in
compatible_table_definition to ensure that they append all of the later
Migration verion's TableDefinition modules. However, the latest
Migration class did not do this and prepended its own TableDefinition
because there was no super method for it to call.

This led to an issue where Action Text migrations started failing on
Rails main, after migration option validation was added in e6da3eb. The
new functionality was not supposed to affect V6_0 Migrations, but it was
because both V6_1 and V7_0 were not calling super.

This commit fixes the issue by correctly calling super in both classes.
It also adds a compatible_table_definition method to Current that
returns the value passed in so that all of the versioned Migrations can
always return super.
This is similar to a [previous commit][1] which ensures that versioned
migrations always call `super` in `compatible_table_definition`. In this
case, these methods are being pulled up to `Current` so that all
subclasses will use a `TableDefinition` class and future developers do
not have to remember to add all of these methods to new versioned
classes when a new one is created.

[1]: 16f8bd7

class BaseCompatibilityTest < ActiveRecord::TestCase
attr_reader :connection
self.use_transactional_tests = false
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MySQL tests failed without transactional_tests disabled on 7-0-stable but they passed on main. From what I can tell, this is due to SchemaMigration no longer inheriting from ActiveRecord::Base: 436277d

Should we disable transactional_tests on main as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to.

fatkodima and others added 2 commits August 23, 2023 02:50
While working on rails#48969, I found that some of the Compatibility test
cases were not working correctly. The tests removed in this commit were
never running the `change_table` migration and so were not actually
testing that `change_table` works correctly. The issue is that the two
migrations created in these tests both have `nil` versions, and so the
Migrator only runs the first one.

This commit refactors the tests so that its easier to test the behavior
of each Migration class version (and I think the rest of the tests
should be updated to use this strategy as well). Additionally, since the
tests are fixed it exposed that `t.change` in a `change_table` is not
behaving as expected so that is fixed as well.

(manually backported to 7-0-stable because it did not apply cleanly)
@rafaelfranca rafaelfranca merged commit 740c400 into rails:7-0-stable Aug 23, 2023
3 checks passed
@skipkayhil skipkayhil deleted the hm-backport-48974 branch August 23, 2023 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants