Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails LHM migration - specify name of index

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

like image 757
xxjjnn Avatar asked Jan 23 '26 17:01

xxjjnn


2 Answers

m.add_unique_index([:long_column, :super_long_column], 'shortened_index_name')

Link to LHM docs for #add_unique_index

like image 159
jimworm Avatar answered Jan 26 '26 09:01

jimworm


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"
like image 28
Dan Rice Avatar answered Jan 26 '26 08:01

Dan Rice



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!