index_exists?

index_exists?(table_name, column_name, options = {})
Instance Public methods

Checks to see if an index exists on a table for a given index definition.

1
2
3
4
5
6
7
8
9
10
11
# Check an index exists
index_exists?(:suppliers, :company_id)
 
# Check an index on multiple columns exists
index_exists?(:suppliers, [:company_id, :company_type])
 
# Check a unique index exists
index_exists?(:suppliers, :company_id, unique: true)
 
# Check an index with a custom name exists
index_exists?(:suppliers, :company_id, name: "idx_company_id")
doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.