instance method
index_exists?
Ruby on Rails 8.0.4
Since v2.3.18Signature
index_exists?(table_name, column_name, **options)
Checks to see if an index exists on a table for a given index definition.
# 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")
# Check a valid index exists (PostgreSQL only)
index_exists?(:suppliers, :company_id, valid: true)
Parameters
-
table_namereq -
column_namereq -
optionskeyrest
Source
# File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 102
def index_exists?(table_name, column_name, **options)
indexes(table_name).any? { |i| i.defined_for?(column_name, **options) }
end
Defined in activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb line 102
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::ConnectionAdapters::SchemaStatements