method
index_name_for_remove
v5.0.0.1 -
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 = {})
protected
Hide source
# File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 1193 def index_name_for_remove(table_name, options = {}) return options[:name] if can_remove_index_by_name?(options) # if the adapter doesn't support the indexes call the best we can do # is return the default index name for the options provided return index_name(table_name, options) unless respond_to?(:indexes) checks = [] if options.is_a?(Hash) checks << lambda { |i| i.name == options[:name].to_s } if options.key?(:name) column_names = Array(options[:column]).map(&:to_s) else column_names = Array(options).map(&:to_s) end if column_names.any? checks << lambda { |i| i.columns.join('_and_') == column_names.join('_and_') } 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