Method: Purview::Databases::Base#create_index

Defined in:
lib/purview/databases/base.rb

#create_index(index, opts = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/purview/databases/base.rb', line 33

def create_index(index, opts={})
  ensure_index_valid_for_database(index)
  table_opts = extract_table_opts(opts)
  table_name = table_name(index.table, table_opts)
  index_opts = extract_index_opts(opts)
  index_name = index_name(
    table_name,
    index,
    index_opts
  )
  with_context_logging("`create_index` for: #{index_name}") do
    with_new_or_existing_connection(opts) do |connection|
      connection.execute(
        create_index_sql(
          table_name,
          index_name,
          index,
          index_opts
        )
      )
    end
  end
  index_name
end