module ActiveRecord
  module ConnectionAdapters
    module SchemaStatements
      def index_name_with_simple(table_name, options)
        shorten_mode =
          case Thread.current[:simple_index_name_shorten_mode]
          when :enable
            true
          when :disable
            false
          else
            ActiveRecord::SimpleIndexName.config.auto_shorten
          end

        if shorten_mode
          if Hash === options && options[:column]
            Array.wrap(options[:column]) * "_and_"
          else
            index_name_without_simple(table_name, options)
          end
        else
          index_name_without_simple(table_name, options)
        end
      end

      alias_method_chain :index_name, :simple
    end
  end
end

module ActiveRecord
  module SimpleIndexName
    module ActiveRecordExt
      def index_name(table_name, options)
        shorten_mode =
          case Thread.current[:simple_index_name_shorten_mode]
          when :enable
            true
          when :disable
            false
          else
            ActiveRecord::SimpleIndexName.config.auto_shorten
          end

        if shorten_mode
          if Hash === options && options[:column]
            Array.wrap(options[:column]) * "_and_"
          else
            super
          end
        else
          super
        end
      end
    end
  end
end

ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval do
  prepend ActiveRecord::SimpleIndexName::ActiveRecordExt
end

Use prepend inspead of alias_method_chain
Use prepend inspead of alias_method_chain

for DEPRECATION WARNING on activesupport 5+

DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead.
From module, you can access the original method using super. (called from <module:SchemaStatements>
at /home/travis/build/sue445/activerecord-simple_index_name/lib/active_record/simple_index_name/active_record_ext.rb:26)
