Module: PGSpecHelper::Indexes
- Included in:
- PGSpecHelper
- Defined in:
- lib/pg_spec_helper/indexes.rb
Instance Method Summary collapse
-
#create_index(schema_name, table_name, column_names, index_name) ⇒ Object
Create an index.
-
#get_index_names(schema_name, table_name) ⇒ Object
get a list of index names for the provided table.
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(<<~SQL) CREATE INDEX #{connection.quote_ident index_name.to_s} ON #{connection.quote_ident schema_name.to_s}.#{connection.quote_ident table_name.to_s} (#{column_names_sql}) SQL end |
#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(<<~SQL, [schema_name.to_s, table_name.to_s]) SELECT indexname FROM pg_indexes WHERE schemaname = $1 AND tablename = $2 ORDER BY indexname; SQL rows.map { |row| row["indexname"].to_sym } end |