Rails Migrations for Large Text Columns

Sometimes you need big text columns in your database.

For example, I’m using bj to asynchronously process large xml files.

By default, the bj database migrations create :text columns types which map to mysql TEXT columns. In mysql, TEXT columns are limited to 64K of data. Luckily there are the MEDIUMTEXT and LONGTEXT column types for holding large data.

So how do you get these types when using Rails migrations?

Just specify the limit:

class AdjustBjColumnTypes < ActiveRecord::Migration
  def self.up
    # this bumps col from TEXT to MEDIUMTEXT in mysql
    change_column :bj_job, :stdin, :text, :limit => 64.kilobytes + 1
    change_column :bj_job_archive, :stdin, :text, :limit => 64.kilobytes + 1
  end

  def self.down
    # this bumps col from MEDIUMTEXT to TEXT in mysql
    change_column :bj_job, :stdin, :text
    change_column :bj_job_archive, :stdin, :text
  end
end

References

Mysql Data Type Storage Requirements

Comment or question via
FYI: This post was migrated over from another blogging engine. If you encounter any issues please let me know on . Thanks.