method
index_name_for_remove
v6.0.0 -
Show latest stable
-
0 notes -
Class: ActiveRecord::ConnectionAdapters::SchemaStatements
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (0)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
index_name_for_remove(table_name, options = {})
private
Hide source
# File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 1269 def index_name_for_remove(table_name, options = {}) return options[:name] if can_remove_index_by_name?(options) checks = [] if options.is_a?(Hash) checks << lambda { |i| i.name == options[:name].to_s } if options.key?(:name) column_names = index_column_names(options[:column]) else column_names = index_column_names(options) end if column_names.present? checks << lambda { |i| index_name(table_name, i.columns) == index_name(table_name, column_names) } end raise ArgumentError, "No name or columns specified" if checks.none? matching_indexes = indexes(table_name).select { |i| checks.all? { |check| check[i] } } if matching_indexes.count > 1 raise ArgumentError, "Multiple indexes found on #{table_name} columns #{column_names}. " "Specify an index name from #{matching_indexes.map(&:name).join(', ')}" elsif matching_indexes.none? raise ArgumentError, "No indexes found on #{table_name} with the options provided." else matching_indexes.first.name end end