Repository: rails/rails
File: activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb (Ruby)

Code before:
        td = create_table_definition(table_name)
        cd = td.new_column_definition(column.name, type, **options)
        ChangeColumnDefinition.new(cd, column.name)
      end

      def rename_column(table_name, column_name, new_column_name) # :nodoc:
        execute("ALTER TABLE #{quote_table_name(table_name)} #{rename_column_for_alter(table_name, column_name, new_column_name)}")
        rename_column_indexes(table_name, column_name, new_column_name)
      end

      def add_index(table_name, column_name, **options) # :nodoc:
        create_index = build_create_index_definition(table_name, column_name, **options)
        return unless create_index

        execute schema_creation.accept(create_index)
      end

      def build_create_index_definition(table_name, column_name, **options) # :nodoc:
        index, algorithm, if_not_exists = add_index_options(table_name, column_name, **options)

        return if if_not_exists && index_exists?(table_name, column_name, name: index.name)

        CreateIndexDefinition.new(index, algorithm)
      end

      # Enables an index to be used by query optimizers.
      #
      #   enable_index(:users, :email)
      #
      # Note: only supported by MySQL version 8.0.0 >= and MariaDB version 10.6.0 >=.
      def enable_index(table_name, index_name)
        raise NotImplementedError unless supports_enabling_use_of_index_for_queries?

        query = <<~SQL
          ALTER TABLE #{quote_table_name(table_name)} ALTER INDEX #{index_name} #{mariadb? ? "NOT IGNORED" : "VISIBLE"}
        SQL
        execute(query)
      end


      # Disables an index not to be used by query optimizers.
      #
      #   disable_index(:users, :email)
      #
      # Note: only supported by MySQL version 8.0.0 >= and MariaDB version 10.6.0 >=.
      def disable_index(table_name, index_name)
        raise NotImplementedError unless supports_disabling_use_of_index_for_queries?

        query = <<~SQL
          ALTER TABLE #{quote_table_name(table_name)} ALTER INDEX #{index_name} #{mariadb? ? "IGNORED" : "INVISIBLE"}
        SQL

Review comment (suggestion):
Nit, I _think_ we can `:nodoc:` these ones since the documentation is already provided by the toplevel schema statements class.

Code after:
        cd = td.new_column_definition(column.name, type, **options)
        ChangeColumnDefinition.new(cd, column.name)
      end

      def rename_column(table_name, column_name, new_column_name) # :nodoc:
        execute("ALTER TABLE #{quote_table_name(table_name)} #{rename_column_for_alter(table_name, column_name, new_column_name)}")
        rename_column_indexes(table_name, column_name, new_column_name)
      end

      def add_index(table_name, column_name, **options) # :nodoc:
        create_index = build_create_index_definition(table_name, column_name, **options)
        return unless create_index

        execute schema_creation.accept(create_index)
      end

      def build_create_index_definition(table_name, column_name, **options) # :nodoc:
        index, algorithm, if_not_exists = add_index_options(table_name, column_name, **options)

        return if if_not_exists && index_exists?(table_name, column_name, name: index.name)

        CreateIndexDefinition.new(index, algorithm)
      end

      def enable_index(table_name, index_name) # :nodoc:
        raise NotImplementedError unless supports_disabling_indexes?

        query = <<~SQL
          ALTER TABLE #{quote_table_name(table_name)} ALTER INDEX #{index_name} #{mariadb? ? "NOT IGNORED" : "VISIBLE"}
        SQL
        execute(query)
      end

      def disable_index(table_name, index_name) # :nodoc:
        raise NotImplementedError unless supports_disabling_indexes?

        query = <<~SQL
          ALTER TABLE #{quote_table_name(table_name)} ALTER INDEX #{index_name} #{mariadb? ? "IGNORED" : "INVISIBLE"}
        SQL
        execute(query)
      end

      def add_sql_comment!(sql, comment) # :nodoc:
        sql << " COMMENT #{quote(comment)}" if comment.present?
        sql
      end

      def foreign_keys(table_name)
        raise ArgumentError unless table_name.present?

        scope = quoted_scope(table_name)