addIndex

@param string       $table
@param string       $type
@param string|array $columns
@param string       $name
@param string       $comment

@return string
778347
public static function addIndex($table, $type, $columns, $name, $comment = null)
    {
        $query = static::getQuery();
        $cols = static::buildIndexDeclare($name, $columns);

        $comment = $comment ? 'COMMENT ' . $query->quote($comment) : '';

        return static::build(
            'ALTER TABLE',
            $query->quoteName($table),
            'ADD',
            strtoupper($type),
            $cols,
            $comment
        );
    }
998985
public function addIndex($columns, array $options = [])
    {
        $action = AddIndex::build($this->table, $columns, $options);
        $this->actions->addAction($action);

        return $this;
    }
401570
public function join(string $table, string $column, string $toColumn, string $type = Query\JoinType::LEFT)
    {
        $alias = $this->joinCurrentAlias++;

        $toAlias = self::cutAlias($toColumn);

        $this->joins[$alias] = [
            'type'   => $type,
            'table'  => $table,
            'column' => $column,
            'to'     => [$toAlias, $toColumn],
        ];

        return $this;
    }
855338
public function addIndex($name, $attrs)
    {
        if (is_string($attrs)) {
            $attrs = ['type' => $attrs];
        }
        $attrs = array_intersect_key($attrs, static::$_indexKeys);
        $attrs += static::$_indexKeys;
        unset($attrs['references'], $attrs['update'], $attrs['delete']);

        if (!in_array($attrs['type'], static::$_validIndexTypes, true)) {
            throw new Exception(sprintf('Invalid index type "%s" in index "%s" in table "%s".', $attrs['type'], $name, $this->_table));
        }
        if (empty($attrs['columns'])) {
            throw new Exception(sprintf('Index "%s" in table "%s" must have at least one column.', $name, $this->_table));
        }
        $attrs['columns'] = (array)$attrs['columns'];
        foreach ($attrs['columns'] as $field) {
            if (empty($this->_columns[$field])) {
                $msg = sprintf(
                    'Columns used in index "%s" in table "%s" must be added to the Table schema first. ' .
                    'The column "%s" was not found.',
                    $name,
                    $this->_table,
                    $field
                );
                throw new Exception($msg);
            }
        }
        $this->_indexes[$name] = $attrs;

        return $this;
    }
293474
public function modifyColumn(
        $name,
        $type = 'text',
        $signed = true,
        $allowNull = true,
        $default = '',
        $comment = '',
        $options = []
    ) {
        if ($name instanceof Column) {
            $column = $name;
            $length = $column->getLength();
            $name = $column->getName();
            $type = $column->getType();
            $signed = $column->getSigned();
            $allowNull = $column->getAllowNull();
            $default = $column->getDefault();
            $position = $column->getPosition();
            $comment = $column->getComment();
            $suffix = $column->getSuffix();
        } else {
            $position = isset($options['position']) ? $options['position'] : null;
            $suffix = isset($options['suffix']) ? $options['suffix'] : null;
        }

        if (!$this->hasColumn($name)) {
            return $this;
        }

        $type = MysqlType::getType($type);
        $length = isset($length) ? $length : MysqlType::getLength($type);
        $length = $length ? '(' . $length . ')' : null;

        $query = MysqlGrammar::modifyColumn(
            $this->getName(),
            $name,
            $type . $length,
            $signed,
            $allowNull,
            $default,
            $position,
            $comment
        );

        // Add suffix
        $query = MysqlGrammar::build($query, $suffix);

        $this->db->setQuery($query)->execute();

        return $this->reset();
    }
1236139
public function addCommentOnColumn($table, $column, $comment)
    {
        $table = $this->db->quoteTableName($table);
        $column = $this->db->quoteColumnName($column);
        $comment = $this->db->quoteValue($comment);

        $this->execute("COMMENT ON COLUMN $table.$column IS $comment;");
    }
898296
public function addCustomFields($fieldName, $type, $addIndex)
    {
        if (!$this->table->hasColumn($fieldName)) {
            $this->{$this->typeMap[$type]}($fieldName);
        }

        if ($addIndex) {
            $this->table->addIndex([$fieldName]);
        }
    }
757763
protected function addIndex($name, $cols)
    {
        if (empty($name)) {
            return Yii::t('podium/flash', 'Installation aborted! Index name missing.');
        }
        if (empty($cols)) {
            return Yii::t('podium/flash', 'Installation aborted! Index columns missing.');
        }
        try {
            $this->db->createCommand()->createIndex($this->getIndexName($name), $this->table, $cols)->execute();
            return $this->returnSuccess(Yii::t('podium/flash', 'Table index {name} has been added', [
                'name' => $this->getIndexName($name)
            ]));
        } catch (Exception $e) {
            return $this->returnError($e->getMessage(), __METHOD__,
                Yii::t('podium/flash', 'Error during table index {name} adding', [
                    'name' => $this->getIndexName($name)
                ])
            );
        }
    }
1137218
public function spatialIndex($columns, $name = null)
    {
        $connection_klass = get_class(\DLModel::getConnectionResolver()->connection());
        if ($connection_klass == 'Illuminate\Database\MySqlConnection') {
            // MySQL: Only MyISAM engine have spatial indexing
            $this->engine = 'MyISAM';
        }

        return $this->indexCommand('spatial', $columns, $name);
    }
1001676
public function addIndex(array $columns, bool $unique = false, string $prefix = null): Table
    {
        $this->indexes[] = new Index($columns, $unique, $prefix);

        return $this;
    }
614726
public function column($name, $type = null, $options = [])
    {
        return $this->addColumn($name, $type, $options);
    }
397432
public function index($columns, $name = null, $algorithm = null)
    {
        $indexName = $name ?? md5(uniqid());

        return $this->indexCommand('index', $columns, $indexName, $algorithm);
    }
6573
public static function alterColumn(
        $operation,
        $table,
        $column,
        $type = 'text',
        $signed = true,
        $allowNull = true,
        $default = null,
        $position = null,
        $comment = ''
    ) {
        $query = static::getQuery();

        $column = $query->quoteName((array) $column);

        return static::build(
            'ALTER TABLE',
            $query->quoteName($table),
            $operation,
            implode(' ', $column),
            $type ?: 'text',
            $signed ? null : 'UNSIGNED',
            $allowNull ? null : 'NOT NULL',
            $default !== false ? 'DEFAULT ' . static::getQuery()->validValue($default) : null,
            $comment ? 'COMMENT ' . $query->quote($comment) : null,
            static::handleColumnPosition($position)
        );
    }
790768
def add_index(columns, index_name = nil)
      options = { name: index_name } if index_name
      migration.add_index(table_name, columns, options || {})
    end
857839
public function setColumnType($name, $type)
    {
        $this->_columns[$name]['type'] = $type;
        $this->_typeMap[$name] = $type;

        return $this;
    }
1155480
public function addIndex($columnName, $type = Table::INDEX_REGULAR) {
        if (!array_key_exists($columnName, $this->getIndexes()) && !array_key_exists($columnName,
                        $this->newIndexes))
                $this->newIndexes[$columnName] = $type;
        return $this;
    }
535511
public static function comment($object, $table, $column, $comment)
    {
        $query = static::getQuery();

        return static::build(
            'COMMENT ON ' . $object,
            $query->quoteName($table) . '.' . $query->quoteName($column),
            'IS',
            $query->quote($comment)
        );
    }