Method: Lhm::Migrator#add_unique_index

Defined in:
lib/lhm/migrator.rb

#add_unique_index(columns, index_name = nil) ⇒ Object

Add a unique index to a table

Examples:


Lhm.change_table(:users) do |m|
  m.add_unique_index(:comment)
  m.add_unique_index([:username, :created_at])
  m.add_unique_index("comment(10)")
end

Parameters:

  • columns (String, Symbol, Array<String, Symbol>)

    A column name given as String or Symbol. An Array of Strings or Symbols for compound indexes. It’s possible to pass a length limit.

  • index_name (String, Symbol) (defaults to: nil)

    Optional name of the index to be created



141
142
143
# File 'lib/lhm/migrator.rb', line 141

def add_unique_index(columns, index_name = nil)
  ddl(index_ddl(columns, true, index_name))
end