SchemaPlus / schema_plus_pg_indexes

Adds support in ActiveRecord for PostgreSQL index expressions and operator classes, as well as a shorthand for case-insensitive indexes
MIT License
30 stars 13 forks source link

[v0.1.12]: Expression index with cast incorrectly dumped #18

Closed felixbuenemann closed 5 years ago

felixbuenemann commented 7 years ago

The following index is created just fine by the migration, but dumped incorrectly in schema.rb:

class AddSearchIndexes < ActiveRecord::Migration
  def change
    change_table :projects do |t|
      t.index expression: '(id::text)', using: 'gin', operator_class: 'gin_trgm_ops', name: 'projects_id_trgm_idx'
    end
  end
end

The resulting schema.rb contains:

create_table "projects", force: :cascade do |t|
  t.index :name=>"projects_id_trgm_idx", :using=>:gin, :expression=>"(id)::text", :operator_class=>"gin_trgm_ops"
end

As can be seen it dumped(id::text) as (id)::text which leads to a postgres syntax error when loading the schema dump:

PG::SyntaxError: ERROR:  syntax error at or near "::"
LINE 1: ...rojects_id_trgm_idx" ON "projects" USING gin ((id)::text gin...

Note: Feel free to close if this has already been fixed in recent versions, I'm still using rails 4.2.8 so I'm stuck on schema_plus_pg_indexes v0.1.12 until I find the time to upgrade rails.

pineapplethief commented 6 years ago

Also experiencing this on Rails 5.1.4, schema_plus_indexes (0.3.0), schema_plus_pg_indexes (0.3.1)

urkle commented 5 years ago

Closing this as expression indexes are natively supported in Rails 5.0+. And operator classes in Rails 5.2+. There will be one Schema+ PG indexes update that will support rails 5.2 (hopefully released in the next day or two). However, as it is no longer needed, that is the last version of this gem. (schema_plus_indexes will still be maintained)