123456789_123456789_123456789_123456789_123456789_

Module: ActiveRecord::Migration::Compatibility::V7_0::LegacyIndexName

Do not use. This module is for internal use only.

Instance Method Summary

Instance Method Details

#expression_column_name?(column_name) ⇒ Boolean (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/migration/compatibility.rb', line 68

def expression_column_name?(column_name)
  column_name.is_a?(String) && /\W/.match?(column_name)
end

#index_name_options(column_names) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/migration/compatibility.rb', line 60

def index_name_options(column_names)
  if expression_column_name?(column_names)
    column_names = column_names.scan(/\w+/).join("_")
  end

  { column: column_names }
end

#legacy_index_name(table_name, options) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/migration/compatibility.rb', line 46

def legacy_index_name(table_name, options)
  if Hash === options
    if options[:column]
      "index_#{table_name}_on_#{Array(options[:column]) * '_and_'}"
    elsif options[:name]
      options[:name]
    else
      raise ArgumentError, "You must specify the index name"
    end
  else
    legacy_index_name(table_name, index_name_options(options))
  end
end