MySQL: Support :size option to change text and blob size - #35071
Merged
Conversation
rafaelfranca
approved these changes
Jan 28, 2019
jeremy
reviewed
Jan 28, 2019
jeremy
left a comment
Member
There was a problem hiding this comment.
Nice feature for Active Record migrations! And great to expand Action Text support to PostgreSQL. Changelog entries for both, too?
Member
Author
|
hm... I've realized that I think that using |
kamipo
force-pushed
the
text_without_limit
branch
from
January 28, 2019 20:43
a0af7d5 to
76b93c9
Compare
kamipo
commented
Jan 28, 2019
Member
Author
There was a problem hiding this comment.
Changed from mediumtext (16 MiB) to longtext (4 GiB).
kamipo
commented
Jan 28, 2019
:size option to change text and blob size
In MySQL, the text column size is 65,535 bytes by default (1 GiB in PostgreSQL). It is sometimes too short when people want to use a text column, so they sometimes change the text size to mediumtext (16 MiB) or longtext (4 GiB) by giving the `limit` option. Unlike MySQL, PostgreSQL doesn't allow the `limit` option for a text column (raises ERROR: type modifier is not allowed for type "text"). So `limit: 4294967295` (longtext) couldn't be used in Action Text. I've allowed changing text and blob size without giving the `limit` option, it prevents that migration failure on PostgreSQL.
kamipo
force-pushed
the
text_without_limit
branch
from
January 28, 2019 21:51
76b93c9 to
1745e90
Compare
kamipo
added a commit
to kamipo/rails
that referenced
this pull request
Apr 7, 2019
…ther options When I've added new `:size` option in rails#35071, I've found that invalid `:limit` and `:precision` raises `ActiveRecordError` unlike other invalid options. I think that is hard to distinguish argument errors and statement invalid errors since the `StatementInvalid` is a subclass of the `ActiveRecordError`. https://github.com/rails/rails/blob/c9e4c848eeeb8999b778fa1ae52185ca5537fffe/activerecord/lib/active_record/errors.rb#L103 ```ruby begin # execute any migration rescue ActiveRecord::StatementInvalid # statement invalid rescue ActiveRecord::ActiveRecordError, ArgumentError # `ActiveRecordError` except `StatementInvalid` is maybe an argument error end ``` I'd say this is the inconsistency worth fixing. Before: ```ruby add_column :items, :attr1, :binary, size: 10 # => ArgumentError add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError ``` After: ```ruby add_column :items, :attr1, :binary, size: 10 # => ArgumentError add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError add_column :items, :attr3, :integer, limit: 10 # => ArgumentError add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError ```
suketa
added a commit
to suketa/rails_sandbox
that referenced
this pull request
Jul 27, 2019
MySQL: Support `:size` option to change text and blob size rails/rails#35071
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.
In MySQL, the text column size is 65,535 bytes by default (1 GiB in
PostgreSQL). It is sometimes too short when people want to use a text
column, so they sometimes change the text size to mediumtext (16 MiB) or
longtext (4 GiB) by giving the
limitoption.Unlike MySQL, PostgreSQL doesn't allow the
limitoption for a textcolumn (raises ERROR: type modifier is not allowed for type "text").
So
limit: 4294967295(longtext) couldn't be used in Action Text.I've allowed changing text and blob size without giving the
limitoption, it prevents that migration failure on PostgreSQL.