Method: ActiveRecord::ConnectionAdapters::SchemaStatements#remove_index
- Defined in:
- activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
#remove_index(table_name, column_name = nil, **options) ⇒ Object
Removes the given index from the table.
Removes the index on branch_id in the accounts table if exactly one such index exists.
remove_index :accounts, :branch_id
Removes the index on branch_id in the accounts table if exactly one such index exists.
remove_index :accounts, column: :branch_id
Removes the index on branch_id and party_id in the accounts table if exactly one such index exists.
remove_index :accounts, column: [:branch_id, :party_id]
Removes the index named by_branch_party in the accounts table.
remove_index :accounts, name: :by_branch_party
Removes the index on branch_id named by_branch_party in the accounts table.
remove_index :accounts, :branch_id, name: :by_branch_party
Checks if the index exists before trying to remove it. Will silently ignore indexes that don’t exist.
remove_index :accounts, if_exists: true
Removes the index named by_branch_party in the accounts table concurrently.
remove_index :accounts, name: :by_branch_party, algorithm: :concurrently
Note: only supported by PostgreSQL.
Concurrently removing an index is not supported in a transaction.
For more information see the “Transactional Migrations” section.
966 967 968 969 970 971 972 |
# File 'activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb', line 966 def remove_index(table_name, column_name = nil, **) return if [:if_exists] && !index_exists?(table_name, column_name, **) index_name = index_name_for_remove(table_name, column_name, ) execute "DROP INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)}" end |