Fix boolean columns triggering MySQL deprecation#54144
Merged
rafaelfranca merged 1 commit intorails:mainfrom Jan 7, 2025
Merged
Fix boolean columns triggering MySQL deprecation#54144rafaelfranca merged 1 commit intorails:mainfrom
rafaelfranca merged 1 commit intorails:mainfrom
Conversation
Previously, when creating a boolean column for a MySQL database
```ruby
class AddSoldToProduct < ActiveRecord::Migration[8.0]
def change
add_column :products, :sold, :boolean
end
end
```
Active Record would create a query like
```SQL
ALTER TABLE `products` ADD `sold` tinyint(1)
```
which would trigger a deprecation warning in MySQL 8.0.17+
```
1681: Integer display width is deprecated and will be removed in a future release.
```
Additionally, starting in MySQL 8.0.19, integer display widths are no
longer included in the output of `SHOW CREATE TABLES` with the exception
of `tinyint(1)` because
> MySQL Connectors make the assumption that TINYINT(1) columns
> originated as BOOLEAN columns; this exception enables them to continue
> to make that assumption.
This commit changes Active Record to use the `boolean` alias for MySQL
(which still results in `tinyint(1)` columns) but does not emit the
deprecation warning for using an integer display width.
```SQL
ALTER TABLE `products` ADD `sold` boolean
```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation / Background
Previously, when creating a boolean column for a MySQL database
Active Record would create a query like
which would trigger a deprecation warning in MySQL 8.0.17+
Additionally, starting in MySQL 8.0.19, integer display widths are no longer included in the output of
SHOW CREATE TABLESwith the exception oftinyint(1)becauseDetail
This commit changes Active Record to use the
booleanalias for MySQL (which still results intinyint(1)columns) but does not emit the deprecation warning for using an integer display width.Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]