Skip to content

Show index operator classes in annotations - #382

Open
kamipo wants to merge 1 commit into
drwl:mainfrom
kamipo:support-index-opclasses
Open

Show index operator classes in annotations#382
kamipo wants to merge 1 commit into
drwl:mainfrom
kamipo:support-index-opclasses

Conversation

@kamipo

@kamipo kamipo commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

PostgreSQL indexes can specify a per column operator class (opclass:), but the index annotation dropped it entirely, so an index like

t.index ["name"], using: :gist, opclass: :gist_trgm_ops

was annotated as (name) USING gist, losing the information that distinguishes it from a plain gist index.

Operator classes are per column, so they are now rendered next to the column, in the same order that ActiveRecord generates the index SQL in (column, opclass, order):

#  index_organizations_on_name_trgm  (name gist_trgm_ops) USING gist

IndexDefinition condenses per column options into a single value when every column shares the same one, so opclasses (and orders) can be either a Hash keyed by column or a bare value. Both are handled now, which also fixes ordered indexes losing their order when every column shares it: t.index [:a, :b], order: :desc was annotated as (a,b) and is now annotated as (a DESC,b DESC).

PostgreSQL indexes can specify a per column operator class (`opclass:`),
but the index annotation dropped it entirely, so an index like

```ruby
t.index ["name"], using: :gist, opclass: :gist_trgm_ops
```

was annotated as `(name) USING gist`, losing the information that
distinguishes it from a plain gist index.

Operator classes are per column, so they are now rendered next to the
column, in the same order that ActiveRecord generates the index SQL in
(column, opclass, order):

```
#  index_organizations_on_name_trgm  (name gist_trgm_ops) USING gist
```

`IndexDefinition` condenses per column options into a single value when
every column shares the same one, so `opclasses` (and `orders`) can be
either a Hash keyed by column or a bare value. Both are handled now,
which also fixes ordered indexes losing their order when every column
shares it: `t.index [:a, :b], order: :desc` was annotated as `(a,b)`
and is now annotated as `(a DESC,b DESC)`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant