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

db/schema.rb turns mediumtext columns into longtext #3931

Closed
pulver opened this issue Dec 10, 2011 · 4 comments · Fixed by #5173
Closed

db/schema.rb turns mediumtext columns into longtext #3931

pulver opened this issue Dec 10, 2011 · 4 comments · Fixed by #5173

Comments

@pulver
Copy link

pulver commented Dec 10, 2011

In Rails 3.1.1 the following migration line creates a column of MySQL type MEDIUMTEXT:

t.text :example, :limit => 0x555555 # this happens to be the maximum length for MEDIUMTEXT. 0x555556 results in LONGTEXT.

however the resulting line in db/schema.rb is

t.text "example", :limit => 16777215

which creates a column of type LONGTEXT.

I would expect that the database column types created by the migration files would be the same as those created by the db/schema.rb file.

@sikachu
Copy link
Member

sikachu commented Dec 29, 2011

Hmm .. that decimal representation actually off a lot. I would expect it to be 5592405. Do you mind sending a pull request with a failing test case (and fix?)

@kennyj
Copy link
Contributor

kennyj commented Jan 7, 2012

I think that I fixed it.
I'll send pull request.

The below definition is mysql side (strange...) behavior.
text(5592405) => mediumtext
text(5592406) => longtext

Thus, I fixed type_to_sql method to return correct type, when the data type is text with limit.

Please see also http://dev.mysql.com/doc/refman/5.5/en/storage-requirements.html

@kennyj
Copy link
Contributor

kennyj commented Feb 25, 2012

I realize mysql side behavior...

If we use latin1 encoding, the limit is 16777215.
But if we use utf-8 encoding, limit is 16777215 / 3 = 5592405

tenderlove added a commit that referenced this issue Feb 27, 2012
Fix type_to_sql with text and limit on mysql/mysql2. Fix GH #3931 (Try again).
@kennyj
Copy link
Contributor

kennyj commented Feb 28, 2012

I'm closing this issue, because the above PR was merged.

@kennyj kennyj closed this as completed Feb 28, 2012
tenderlove added a commit that referenced this issue Feb 29, 2012
[3-2-stable] Fix type_to_sql with text and limit on mysql/mysql2. Fix GH #3931
tenderlove added a commit that referenced this issue Feb 29, 2012
[3-1-stable] Fix type_to_sql with text and limit on mysql/mysql2. Fix GH #3931
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants