Module: PGSpecHelper::Indexes

Included in:
PGSpecHelper
Defined in:
lib/pg_spec_helper/indexes.rb

Instance Method Summary collapse

Instance Method Details

#create_index(schema_name, table_name, column_names, index_name) ⇒ Object

Create an index



6
7
8
9
10
11
12
# File 'lib/pg_spec_helper/indexes.rb', line 6

def create_index schema_name, table_name, column_names, index_name
  column_names_sql = column_names.join(", ")
  connection.exec("    CREATE INDEX \#{connection.quote_ident index_name.to_s}\n      ON \#{connection.quote_ident schema_name.to_s}.\#{connection.quote_ident table_name.to_s} (\#{column_names_sql})\n  SQL\nend\n")

#get_index_names(schema_name, table_name) ⇒ Object

get a list of index names for the provided table



15
16
17
18
19
20
21
22
23
24
# File 'lib/pg_spec_helper/indexes.rb', line 15

def get_index_names schema_name, table_name
  rows = connection.exec_params("    SELECT indexname\n    FROM pg_indexes\n    WHERE schemaname = $1\n      AND tablename = $2\n    ORDER BY indexname;\n  SQL\n  rows.map { |row| row[\"indexname\"].to_sym }\nend\n", [schema_name.to_s, table_name.to_s])