toy / dump

Rails app rake and capistrano tasks to create and restore dumps of database and assets
MIT License
89 stars 14 forks source link

Mediumtext transforms to Longtext #1

Closed cypok closed 13 years ago

cypok commented 14 years ago

I've got mysql database. One table has column with type mediumtext (16Mb). So I create dump, restore it, .. And column transforms to longtext (2Gb)!

$ rake db:drop && rake db:create && rake db:migrate
$ ack frames db/schema.rb
    t.text     "frames",     :limit => 16777215
$ rake dump:create && rake dump:restore
$ ack frames db/schema.rb
    t.text     "frames",     :limit => 2147483647

I've tried to find out what happens, but couldn't. Can you?

toy commented 14 years ago

First — thanks for pointing on ack, it is much better than grep :)

About your issue: dump uses standard rails rake tasks db:schema:dump and db:schema:load, to dump schema, so it is most probably rails/mysql issue. I tried to create table with limit of 16777215 (16.megabytes - 1) and mysql describe said that it is longtext, not mediumtext (with rails 3 run rails db and run describe …;). Further investigation gave me that maximum limit which creates mediumtext is 5592405 (it is (4 + 1).megabytes + (256 + 64 + 16 + 4 + 1).kilobytes + (256 + 64 + 16 + 4 + 1)) and adding 1 to it gives longtext, very strange number and I think that this has something to do with utf-8.

Also rails is not beware of such things, so if you set limit in migration for example to 4.megabytes and migrate, you will have mediumtext in db, but shema will get limit of 16777215, than, if you just load schema with rake db:schema:load, schema will still have limit of 16777215, but mysql will contain longtext, and if you run rake db:schema:dump, shema will get its limit of 2147483647.