SchemaPlus / schema_plus

SchemaPlus provides a collection of enhancements and extensions to ActiveRecord
Other
679 stars 84 forks source link

Index name not respected when adding an index in `change_table` #222

Closed fj closed 9 years ago

fj commented 9 years ago

A migration contains this index addition:

    change_table :streams do |t|
      t.index(
        expression: "dependencies->'stream_ids'",
        using: :gin,
        name: 'index_streams_on_dependencies_stream_ids',
      )
    end

but SchemaPlus doesn't seem to respect the name field and an automatic one is generated:

ArgumentError: Index name 'index_streams_on_{:expression=>"dependencies->'stream_ids'", :using=>:gin, :name=>"index_streams_on_dependencies_stream_ids"}' on table 'streams' is too long; the limit is 63 characters

If the equivalent thing is done with add_index then everything is fine:

    add_index(
      :streams,
      :dependencies,
      # note parentheses required here to get correct double-parentheses in result
      expression: "(dependencies->'stream_ids')",
      using: :gin,
      name: 'index_streams_on_dependencies_stream_ids'
    )

then name is respected.

Running from schema_plus @ master, psql @ 9.4.1.

ronen commented 9 years ago

Released schema_plus_pg_indexes v0.1.5 with this fixed.

fj commented 9 years ago

:+1:, thanks for the fix, @ronen. I've amended the title to be slightly more specific for posterity.