Rails migrations for large text columns
May 24th, 2008
Rails
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


1 Comment
Commenting is closed for this article.