I have a migration:
class AddGinIndexToContacts < ActiveRecord::Migration
def up
execute("CREATE INDEX contacts_search_idx ON contacts USING gin (first_name gin_trgm_ops, last_name gin_trgm_ops, name gin_trgm_ops)")
end
def down
execute("DROP INDEX contacts_search_idx")
end
end
It generates this code in schema.rb
:
add_index "contacts", ["first_name", "last_name", "name"], name: "contacts_search_idx", using: :gin
and later, when I execute rake db:schema:load
it generates wrong sql:
CREATE INDEX "contacts_search_idx" ON "contacts" USING gin ("first_name", "last_name", "name")
Firstly, it says:
ERROR: data type character varying has no default operator class for access method "gin"
Secondly, there are lost gin_trgm_ops
.
How to make it works?
Rails 4.2