Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Fulltext index with Rails 2.3.2 (migration problem)

I'm using MySQL fulltext indexes in a Rails 2.3.2 App. I added the index via native SQL in my migration. But there is a known issue causing problems with the schema.rb. Rails doesn't understand fulltext indexes and tries to create a normal index. This will cause an error when creating the database from schema.rb (eg testing, specs, etc.):

Mysql::Error: BLOB/TEXT column 'text' used in key specification without a key length: CREATE  INDEX `fulltext_sms` ON `sms` (`text`)

Is there a way to solve this issue in Rails 2.3.2 without monkey-patching Rails? And if not, what's the best way to deals with this?

Thank you!

My migration:

class FulltextIndexCustomersSmsMessage < ActiveRecord::Migration
  def self.up
    execute('ALTER TABLE sms ENGINE = MyISAM')
    execute('ALTER TABLE customers ENGINE = MyISAM')
    execute('CREATE FULLTEXT INDEX fulltext_sms ON sms (text(500))')
    execute('CREATE FULLTEXT INDEX fulltext_customer ON customers (fullname(255))')
  end

  def self.down
    execute('ALTER TABLE sms ENGINE = innodb')
    execute('ALTER TABLE customers ENGINE = innodb')
    execute('DROP INDEX fulltext_sms ON sms')
    execute('DROP INDEX fulltext_customer ON customers')
  end
end

schema.rb:

add_index "sms", ["text"], :name => "fulltext_sms"
like image 635
Ole Spaarmann Avatar asked Apr 17 '09 07:04

Ole Spaarmann


1 Answers

I think you need to set this in your environment.rb:

config.active_record.schema_format = :sql

Here the reference: https://rails.lighthouseapp.com/projects/8994/tickets/74-problem-with-tests-and-custom-mysql-fulltext-indexes

like image 186
newtonapple Avatar answered Oct 18 '22 21:10

newtonapple