Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9254 (new enhancement)

Opened 2 years ago

Last modified 2 years ago

[patch] add_index with a prefix length in db:migration

Reported by: ayucat Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: edge
Severity: normal Keywords: db:migration
Cc: tarmo

Description

Sometimes it is needed to add a index of a blob/varchar column with a prefix length (e.g. the first N characters in strings) in db:migration. I made a fix as follows for this problem (this fix might works only for MySQL). If you have any better solution than this fix, I hope you show that in this list. I plan to use a index of varchar with a limitted length as follows:

CREATE TABLE test (varchar_col VARCHAR(255), INDEX(varchar_col(5)));

Attachments

add_index_with_prefix_length.patch (1.1 kB) - added by ayucat on 08/13/07 10:45:57.

Change History

08/13/07 10:45:57 changed by ayucat

  • attachment add_index_with_prefix_length.patch added.

08/13/07 12:49:12 changed by tarmo

  • cc set to tarmo.

Could you add a test for the change? I'm not sure if this is something that could get into core if it really is mysql-specific. I think you're also missing schema-dumping support, so the length parameter will not get to schema.rb.

08/14/07 20:02:37 changed by ayucat

Thank you for your response. I think a test for this change and a support of schema dump are necessary. I don't think this change might be integrated in the Rails core... Anyway I'll begin with coding deficiency and review the code...