Using LHM (Large Hadron Migrator) there is syntax documentation to add indexes:
require 'lhm'
class SomeMigration < ActiveRecord::Migration
def self.up
Lhm.change_table :foos do |m|
m.add_unique_index [:bar_id, :baz] # add_index if you don't want uniqueness
end
end
def self.down
Lhm.change_table :foos do |m|
m.remove_index [:bar_id, :baz]
end
end
end
How can a specific name for the index be specified in LHM? For adding and removing
I am concerned I will hit the index name length limit as I am using many columns
m.add_unique_index([:long_column, :super_long_column], 'shortened_index_name')
Link to LHM docs for #add_unique_index
https://github.com/soundcloud/lhm/pull/84
Looks like this has changed since the approved answer was suggested. Now you should not specify name: or index_name:, just pass it as the second argument:
m.add_unique_index [:bar_id, :baz], "shortened_index_name"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With