Skip to content

Commit 0731608

Browse files
authored
Merge pull request #3420 from leofeyer/hotfix/index-length
Index length can be a `string`: ensure that it is an integer when read by the `MySqlSchemaManager`
2 parents f28f3a8 + 0608372 commit 0731608

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null
6868
} elseif (strpos($v['index_type'], 'SPATIAL') !== false) {
6969
$v['flags'] = ['SPATIAL'];
7070
}
71-
$v['length'] = $v['sub_part'] ?? null;
71+
$v['length'] = isset($v['sub_part']) ? (int) $v['sub_part'] : null;
7272

7373
$tableIndexes[$k] = $v;
7474
}

tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,19 @@ public function testSpatialIndex()
107107
self::assertTrue($indexes['s_index']->hasFlag('spatial'));
108108
}
109109

110+
public function testIndexWithLength() : void
111+
{
112+
$table = new Table('index_length');
113+
$table->addColumn('text', 'string', ['length' => 255]);
114+
$table->addIndex(['text'], 'text_index', [], ['lengths' => [128]]);
115+
116+
$this->schemaManager->dropAndCreateTable($table);
117+
118+
$indexes = $this->schemaManager->listTableIndexes('index_length');
119+
self::assertArrayHasKey('text_index', $indexes);
120+
self::assertSame([128], $indexes['text_index']->getOption('lengths'));
121+
}
122+
110123
/**
111124
* @group DBAL-400
112125
*/

0 commit comments

Comments
 (0)