DoctrineMigrations\Version20161014100031::createIndex PHP Method

createIndex() protected method

protected createIndex ( Doctrine\DBAL\Schema\Schema $schema, string $tableName, array $columns, string $indexName, array $length = [] )
$schema Doctrine\DBAL\Schema\Schema
$tableName string
$columns array
$indexName string
$length array
    protected function createIndex(Schema $schema, $tableName, array $columns, $indexName, array $length = array())
    {
        if (!$schema->hasTable($tableName)) {
            return false;
        }
        $table = $schema->getTable($tableName);
        if (!$table->hasIndex($indexName)) {
            if ($this->connection->getDatabasePlatform()->getName() == "mysql" && !empty($length)) {
                $cols = array();
                foreach ($length as $column => $len) {
                    $cols[] = sprintf('%s(%d)', $column, $len);
                }
                $this->addSql('CREATE INDEX ' . $indexName . ' ON ' . $tableName . '(' . implode(', ', $cols) . ');');
            } else {
                $table->addIndex($columns, $indexName);
            }
            return true;
        }
        return false;
    }