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

Merged
merged 1 commit into from Jan 29, 2019

Conversation

Projects
None yet
3 participants
@kamipo
Copy link
Member

kamipo commented Jan 28, 2019

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.

@jeremy
Copy link
Member

jeremy left a comment

Nice feature for Active Record migrations! And great to expand Action Text support to PostgreSQL. Changelog entries for both, too?

@kamipo

This comment has been minimized.

Copy link
Member Author

kamipo commented Jan 28, 2019

hm... I've realized that limit: 16777215 is ignored on PostgreSQL adapter, so Action Text originally work on PostgreSQL.

when "text"
# PostgreSQL doesn't support limits on text columns.
# The hard limit is 1GB, according to section 8.3 in the manual.
case limit
when nil, 0..0x3fffffff; super(type)
else raise(ActiveRecordError, "The limit on text can be at most 1GB - 1byte.")

I think that using limit: 16777215 (mediumtext 16 MiB) not limit: 4294967295 (longtext 4 GiB) is to ignore the limit option on PostgreSQL adapter.
So how about changing mediumtext to longtext for MySQL? 16 MiB is still too shorter than PostgreSQL's limit (1 GiB).

@kamipo kamipo force-pushed the kamipo:text_without_limit branch from a0af7d5 to 76b93c9 Jan 28, 2019

@@ -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

This comment has been minimized.

@kamipo

kamipo Jan 28, 2019

Author Member

Changed from mediumtext (16 MiB) to longtext (4 GiB).

@kamipo kamipo changed the title Allow using Action Text on PostgreSQL MySQL: Support `:size` option to change text and blob size Jan 28, 2019

Allow changing text and blob size without giving the `limit` option
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 kamipo force-pushed the kamipo:text_without_limit branch from 76b93c9 to 1745e90 Jan 28, 2019

@rails-bot rails-bot bot added the actionmailbox label Jan 28, 2019

@kamipo kamipo merged commit 8309cd2 into rails:master Jan 29, 2019

2 checks passed

codeclimate All good!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@kamipo kamipo deleted the kamipo:text_without_limit branch Jan 29, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment