Rails and Postgres Hstore: Can you add an index in a migration?
In Rails 4, you can now do something like this in a migration:
add_index :products, :data, using: :gin
Yes! You can make another migration and use the 'execute' method... like so:
class IndexProductsGinData < ActiveRecord::Migration def up execute "CREATE INDEX products_gin_data ON products USING GIN(data)" end def down execute "DROP INDEX products_gin_data" endend
UPDATE: You might also want to specify this line in config/application.rb:
config.active_record.schema_format = :sql
You can read about it here: http://apidock.com/rails/ActiveRecord/Base/schema_format/class