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 change_column not setting precision for sqlite #49090

Merged
merged 1 commit into from
Sep 1, 2023

Conversation

skipkayhil
Copy link
Member

Motivation / Background

There were a few 6.1 migration compatibility fixes in previous commits. Most importantly, those commits reorganized some of the compatibility tests to ensure that the tests would run against every Migration version. To continue the effort of improving test coverage for Migration compatibility, this commit converts tests for create_table and change_column setting the correct precision on datetime columns.

While the create_table tests all pass, the change_column test did not pass for 7.0 versioned Migrations on sqlite. This was due to the sqlite adapter not using new_column_definition to set the options on the new column (new_column_definition is where precision: 6 gets set if no precision is specified). This happens because columns can't be modified in place in sqlite and instead the whole table must be recreated and the data copied. Before this commit, change_column would use the options of the existing column as a base and merge in the exact options (and type) passed to change_column.

Detail

This commit changes the change_column method to replace the existing column without using the existing options. This ensures that precision: 6 is set consistently across adapters when change_column is used to create a datetime column.

Additional information

If this is backport worthy I can make another PR since the tests will not cherry-pick cleanly onto 7-0-stable.

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.

There were a few 6.1 migration compatibility fixes in [previous][1]
[commits][2]. Most importantly, those commits reorganized some of the
compatibility tests to ensure that the tests would run against every
Migration version. To continue the effort of improving test coverage for
Migration compatibility, this commit converts tests for create_table and
change_column setting the correct precision on datetime columns.

While the create_table tests all pass, the change_column test did not
pass for 7.0 versioned Migrations on sqlite. This was due to the sqlite
adapter not using new_column_definition to set the options on the new
column (new_column_definition is where precision: 6 gets set if no
precision is specified). This happens because columns can't be modified
in place in sqlite and instead the whole table must be recreated and the
data copied. Before this commit, change_column would use the options
of the existing column as a base and merge in the exact options (and
type) passed to change_column.

This commit changes the change_column method to replace the existing
column without using the existing options. This ensures that precision:
6 is set consistently across adapters when change_column is used to
create a datetime column.

[1]: c2f838e
[2]: 9b07b2d
@rafaelfranca rafaelfranca merged commit cdbc9b7 into rails:main Sep 1, 2023
4 checks passed
@rafaelfranca rafaelfranca deleted the hm-change-column-precision-6 branch September 1, 2023 18:21
@rafaelfranca
Copy link
Member

Can you open the benchmark PR?

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

2 participants