Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

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

Comments

Projects
None yet
3 participants

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.

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?)

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 added a commit to kennyj/rails that referenced this issue Jan 25, 2012

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

Merge pull request #5173 from kennyj/fix_3931-2
Fix type_to_sql with text and limit on mysql/mysql2. Fix GH #3931 (Try again).
Contributor

kennyj commented Feb 28, 2012

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

@kennyj kennyj closed this Feb 28, 2012

tenderlove added a commit that referenced this issue Feb 29, 2012

Merge pull request #5206 from kennyj/fix_5173-32
[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

Merge pull request #5207 from kennyj/fix_5173-31
[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