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

Ticket #8733 (closed enhancement: incomplete)

Opened 1 year ago

Last modified 1 year ago

[PATCH] add_index to support multiple, separate indexes

Reported by: mislav Assigned to: core
Priority: normal Milestone: 1.x
Component: ActiveRecord Version: edge
Severity: normal Keywords: index
Cc:

Description

In my migrations, I have a lot of repetition for separate indices on the same table:

add_index :table, :foo
add_index :table, :bar

This patch makes this possible:

add_index :table, :foo, :bar

Note that this is different from indexes with multiple columns:

add_index :table, [:foo, :bar]

This patch makes these possible, also:

add_index :table, :foo, :bar, :type => 'FULLTEXT'
# CREATE FULLTEXT INDEX ...
remove_index :table, :foo, :bar

add_index :table, :name => 'foo', :column_sql => 'foo DESC, bar ASC'
# CREATE INDEX foo ON table (foo DESC, bar ASC)

The patch also does a nice refactoring of remove_index logic in adapters and it fixes incorrect documentation about index naming conventions.

Attachments

indexes.diff (13.8 kB) - added by mislav on 06/23/07 19:14:51.

Change History

06/23/07 19:14:51 changed by mislav

  • attachment indexes.diff added.

06/23/07 19:48:23 changed by mislav

Slightly related: #5630

06/23/07 20:53:27 changed by matt

+1 very useful patch IMHO

06/24/07 01:10:58 changed by lifofifo

I don't think it's worth the confusion between :x, :y & [:x, :y].

And you can always do something like following to avoid duplication :

[:a, :b, :c, [:d, :e]].each do |i| add_index :table, i; end

:type and :column_sql might be useful.

06/24/07 01:38:30 changed by mislav

  • status changed from new to closed.
  • resolution set to incomplete.

You're right. Rick Olson complained about the very same thing. I'll drop the infinite arguments list, but will work more on extra options for specific backends/index types. I totally forgot I need to work on the schema dumper also.