Create a default index name for the table.

This function ist used by addIndex() and dropIndex();

@param string $table
@param array $columns
@param boolean $unique
@return string
345493
protected function createIndexName($table, array $columns, $unique = false)
    {
        $index = strtolower($table . '_' . implode('_', $columns) . '_' . ($unique ? 'unique' : 'index'));

        return str_replace(['-', '.'], '_', $index);
    }
1065588
public function unique(string $indexName): IndexColumnsDefiner
    {
        return new IndexColumnsDefiner(function (array $columnNames) use ($indexName) {
            $this->indexes[] = new Index($this->orm->getNamespace() . $indexName, true, $columnNames);
        });
    }
508227
public function dropUnique($columns)
    {
        $unique = new Unique($columns, $this);

        $this->actions[] =  function () use ($unique) {
             return $this->manipulation->drop($unique);
        };

        return $this;
    }
1133914
public function addUniqueIndex( $table,$columns ) {
		$table = $this->safeTable($table);
		sort($columns); //else we get multiple indexes due to order-effects
		foreach($columns as $k=>$v) {
			$columns[$k]= $this->safeColumn($v);
		}
		$r = $this->adapter->get("SHOW INDEX FROM $table");
		$name = 'UQ_'.sha1(implode(',',$columns));
		if ($r) {
			foreach($r as $i) { 
				if (strtoupper($i['Key_name'])== strtoupper($name)) {
					return;
				}
			}
		}
		$sql = "ALTER TABLE $table
                ADD CONSTRAINT UNIQUE $name (".implode(',',$columns).")";
		$this->adapter->exec($sql);
	}
962438
public function createIndex($name, $target, $unique = false, $table = null)
    {
        return $this->db->createIndex($table, $name, $target, $unique)
                        ->execute();
    }
1249460
protected function _addIndex($index_cols, $search_cols, $unique, $length)
    {
        if (!is_array($index_cols))
            $index_cols = array($index_cols);
        $quotedCols = array_map(array($this->db, 'quotekey'), $index_cols);
        if (preg_match('/mysql/', $this->db->driver()))
            foreach($quotedCols as $i=>&$col)
                if(strtoupper($search_cols[$index_cols[$i]]['type']) == 'TEXT')
                    $col.='('.$length.')';
        $cols = implode(',', $quotedCols);
        $name = $this->assembleIndexKey($index_cols,$this->name);
        $name = $this->db->quotekey($name);
        $table = $this->db->quotekey($this->name);
        $index = $unique ? 'UNIQUE INDEX' : 'INDEX';
        $cmd = array(
            'pgsql|sqlite2?|ibm|mssql|sybase|dblib|odbc|sqlsrv' =>
                "CREATE $index $name ON $table ($cols);",
            'mysql' => //ALTER TABLE is used because of MySQL bug #48875
                "ALTER TABLE $table ADD $index $name ($cols);",
        );
        $query = $this->findQuery($cmd);
        $this->queries[] = $query;
    }
1268857
public function unique($table, $column = null, $id = false)
    {
        $rule = $table;

        // Take any argument after the 3 defined ones
        $args = array_slice(func_get_args(), 3);

        if (isset($column)) {
            $rule .= ",$column";
        }

        // A NULL value is a valid one for the validator,
        // so an explicit FALSE is checked
        if ($id !== false) {
            if ($id === null) {
                $rule .= ',NULL';
            }
            else {
                $rule .= ",$id";
            }
        }

        if ($args) {
            // Add optional arguments
            foreach ($args as $arg) {
                $rule .= ",$arg";
            }
        }

        $this->addRule("unique:$rule");
        return $this;
    }
867288
public function removeIndex($columns)
    {
        $action = DropIndex::build($this->table, is_string($columns) ? [$columns] : $columns);
        $this->actions->addAction($action);

        return $this;
    }
918365
protected function addUniqueConstraint(Table $table)
    {
        $unique = new Unique($this->getColumnForParameter('slug_column'));
        $unique->setName($table->getCommonName() . '_slug');
        $unique->addColumn($table->getColumn($this->getParameter('slug_column')));
        if ($this->getParameter('scope_column')) {
            $unique->addColumn($table->getColumn($this->getParameter('scope_column')));
        }
        $table->addUnique($unique);
    }
745204
protected function createIndex($name, array $columns)
    {
        $index = new Index($name);
        $index->setColumns($columns);
        $index->resetColumnsSize();

        $this->addIndex($index);

        return $index;
    }
461033
protected function createIndexName($type, array $columns)
    {
        $index = strtolower($type . '_' . implode('_', $columns));

        return str_replace(['-', '.'], '_', $index);
    }
1234563
public function columnsFrom($table, string $column, string ...$columns)
    {
        $this->from($table);

        list($tableAlias, $tableName) = $this->dialect()->parseTable($table);

        if (!$tableAlias) {
            $tableAlias = $tableName;
        }

        array_unshift($columns, $column);

        foreach ($columns as &$column) {
            $column = $tableAlias . '.' . $column;
        }
        unset($column);

        $this->columns(...$columns);

        return $this;
    }
220920
public function addIndex($columns, $unique = FALSE, $length = 20)
    {
        if (!is_array($columns))
            $columns = array($columns);
        $existingCol = $this->columns;
        foreach ($existingCol as &$col)
            $col = $col->getColumnArray();
        $allCols = array_merge($this->getCols(true), $existingCol);
        parent::_addIndex($columns, $allCols, $unique, $length);
    }
418814
public function addIndex($table, $column, $name)
    {
        $sql = sprintf('ALTER TABLE %s ADD INDEX %s(%s)', $table, $name, $column);

        // Execute query
        $stmt = $this->connection->prepare($sql);
        return $stmt->execute();
    }
994141
public function generateIndexName($columns)
    {
        $parts = [];
        foreach ($columns as $column => $order) {
            $parts[] = $column . '_' . $order;
        }
        return implode('_', $parts);
    }
243162
public function indexExists( $table, $columns = [ ] )
    {
        if ( !is_array( $columns ) )
        {
            throw new Exception( 'columns must be an array' );
        }

        $query = "SELECT * FROM information_schema.statistics WHERE table_schema =
                 ? AND table_name = ? AND ";

        $params = [ $this->name, $table ];

        foreach ( $columns as $column )
        {
            $query .= "column_name = ? OR ";
            $params[ ] = &$column;
        }

        $query = rtrim( $query, ' OR ' );

        $statement = $this->database->prepare( $query );
        $statement->execute( $params );

        $result = $statement->fetchAll();

        return !empty( $result );
    }
548483
public function dropIndex(array $columns): AbstractTable
    {
        if (empty($schema = $this->current->findIndex($columns))) {
            throw new SchemaException(
                "Undefined index ['" . join("', '", $columns) . "'] in '{$this->getName()}'"
            );
        }

        //Dropping index from current schema
        $this->current->forgetIndex($schema);

        return $this;
    }