public function onSchemaIndexDefinition(SchemaIndexDefinitionEventArgs $event): void
    {
        // Skip for doctrine/dbal >= 2.9
        if (method_exists(AbstractPlatform::class, 'supportsColumnLengthIndexes')) {
            return;
        }

        $connection = $event->getConnection();

        if (!$connection->getDatabasePlatform() instanceof MySqlPlatform) {
            return;
        }

        $data = $event->getTableIndex();

        // Ignore primary keys
        if ('PRIMARY' === $data['name']) {
            return;
        }

        $columns = [];
        $query = sprintf("SHOW INDEX FROM %s WHERE Key_name='%s'", $event->getTable(), $data['name']);
        $result = $connection->executeQuery($query);

        while ($row = $result->fetch()) {
            if (null !== $row['Sub_part']) {
                $columns[] = sprintf('%s(%s)', $row['Column_name'], $row['Sub_part']);
            } else {
                $columns[] = $row['Column_name'];
            }
        }

        $event->setIndex(
            new Index(
                $data['name'],
                $columns,
                $data['unique'],
                $data['primary'],
                $data['flags'],
                $data['options']
            )
        );

        $event->preventDefault();
    }
public function onSchemaIndexDefinition(SchemaIndexDefinitionEventArgs $event): void
    {
        // Skip for doctrine/dbal >= 2.9
        if (method_exists(AbstractPlatform::class, 'supportsColumnLengthIndexes')) {
            return;
        }

        $connection = $event->getConnection();

        if (!$connection->getDatabasePlatform() instanceof MySqlPlatform) {
            return;
        }

        $data = $event->getTableIndex();

        // Ignore primary keys
        if ('PRIMARY' === $data['name']) {
            return;
        }

        $columns = [];
        $query = sprintf("SHOW INDEX FROM %s WHERE Key_name='%s'", $event->getTable(), $data['name']);
        $result = $connection->executeQuery($query);

        while ($row = $result->fetch()) {
            if (null !== $row['Sub_part']) {
                $columns[] = sprintf('%s(%s)', $row['Column_name'], $row['Sub_part']);
            } else {
                $columns[] = $row['Column_name'];
            }
        }

        $event->setIndex(
            new Index(
                $data['name'],
                $columns,
                $data['unique'],
                $data['primary'],
                $data['flags'],
                $data['options']
            )
        );

        $event->preventDefault();
    }
public function onSchemaIndexDefinition ( SchemaIndexDefinitionEventArgs $ event ) : void { // Skip for doctrine/dbal >= 2.9 if ( method_exists ( AbstractPlatform :: class , 'supportsColumnLengthIndexes' ) ) { return ; } $ connection = $ event -> getConnection ( ) ; if ( ! $ connection -> getDatabasePlatform ( ) instanceof MySqlPlatform ) { return ; } $ data = $ event -> getTableIndex ( ) ; // Ignore primary keys if ( 'PRIMARY' === $ data [ 'name' ] ) { return ; } $ columns = [ ] ; $ query = sprintf ( "SHOW INDEX FROM %s WHERE Key_name='%s'" , $ event -> getTable ( ) , $ data [ 'name' ] ) ; $ result = $ connection -> executeQuery ( $ query ) ; while ( $ row = $ result -> fetch ( ) ) { if ( null !== $ row [ 'Sub_part' ] ) { $ columns [ ] = sprintf ( '%s(%s)' , $ row [ 'Column_name' ] , $ row [ 'Sub_part' ] ) ; } else { $ columns [ ] = $ row [ 'Column_name' ] ; } } $ event -> setIndex ( new Index ( $ data [ 'name' ] , $ columns , $ data [ 'unique' ] , $ data [ 'primary' ] , $ data [ 'flags' ] , $ data [ 'options' ] ) ) ; $ event -> preventDefault ( ) ; }
Adds the index length on MySQL platforms for Doctrine DBAL <2.9.
Adds the index length on MySQL platforms for Doctrine DBAL <2 . 9 .