Reputation: 16749
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"
Upvotes: 7
Views: 3914
Reputation: 4133
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
Upvotes: 5
Reputation: 2072
How about using one of the full-text search engines that can be easily plugged into Rails? Saves you the trouble of doing it all yourself with mysql. Two good options, that provide lots of customization, are:
Upvotes: 1