Can I change my migrations depending on the database adapter? How will it reflects in the schema.rb?

StackOverflow https://stackoverflow.com/questions/3988820

  •  10-10-2019
  •  | 
  •  

Question

Specifically, I want to add an spatial index in a multi_polygon column. This works nicely in PostgreSQL but not in MySQL, so I was thinking of somthing like:

create_table :figures do |t|
  t.multi_polygon :polygon
end

add_index :figures, :polygon if database_adapter == :postgresql

Is it possible and a good idea?

Was it helpful?

Solution

You can pass index this way

add_index(:figures, [:polygon,:extra1,:extra2], :name => 'fig_poly')

This will work on mysql,postgresql,oracle and db2.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top