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
MySQL: Support :size
option to change text and blob size
#35071
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice feature for Active Record migrations! And great to expand Action Text support to PostgreSQL. Changelog entries for both, too?
actiontext/test/dummy/db/migrate/2018052816_create_action_text_tables.rb
Outdated
Show resolved
Hide resolved
activerecord/lib/active_record/connection_adapters/mysql/schema_definitions.rb
Show resolved
Hide resolved
activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb
Show resolved
Hide resolved
hm... I've realized that rails/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb Lines 553 to 558 in 5a8f0c7
I think that using |
a0af7d5
to
76b93c9
Compare
@@ -2,7 +2,7 @@ class CreateActionTextTables < ActiveRecord::Migration[6.0] | |||
def change | |||
create_table :action_text_rich_texts do |t| | |||
t.string :name, null: false | |||
t.text :body, limit: 16777215 | |||
t.text :body, size: :long |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed from mediumtext (16 MiB) to longtext (4 GiB).
activerecord/lib/active_record/connection_adapters/mysql/schema_definitions.rb
Show resolved
Hide resolved
: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.
76b93c9
to
1745e90
Compare
…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 ```
MySQL: Support `:size` option to change text and blob size rails/rails#35071
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 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
limit
option, it prevents that migration failure on PostgreSQL.