mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 13:58:55 +08:00
Fixes #13814: MySQL unique index names can now contain spaces
This commit is contained in:
committed by
Alexander Makarov
parent
940377ce56
commit
a2a79a70eb
@ -4,6 +4,7 @@ Yii Framework 2 Change Log
|
|||||||
2.0.14 under development
|
2.0.14 under development
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
|
- Enh #13814: MySQL unique index names can now contain spaces (df2)
|
||||||
- Bug #15300: Fixed "Cannot read property 'style' of undefined" error at the error screen (vitorarantes)
|
- Bug #15300: Fixed "Cannot read property 'style' of undefined" error at the error screen (vitorarantes)
|
||||||
- Enh #15426: Added abilitiy to create and drop database views (igravity, vladis84)
|
- Enh #15426: Added abilitiy to create and drop database views (igravity, vladis84)
|
||||||
- Enh #10186: Use native `hash_equals` in `yii\base\Security::compareString()` if available, throw exception if non-strings are compared (aotd1, samdark)
|
- Enh #10186: Use native `hash_equals` in `yii\base\Security::compareString()` if available, throw exception if non-strings are compared (aotd1, samdark)
|
||||||
|
|||||||
@ -447,11 +447,11 @@ SQL;
|
|||||||
$sql = $this->getCreateTableSql($table);
|
$sql = $this->getCreateTableSql($table);
|
||||||
$uniqueIndexes = [];
|
$uniqueIndexes = [];
|
||||||
|
|
||||||
$regexp = '/UNIQUE KEY\s+([^\(\s]+)\s*\(([^\(\)]+)\)/mi';
|
$regexp = '/UNIQUE KEY\s+\`(.+)\`\s*\((\`.+\`)+\)/mi';
|
||||||
if (preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER)) {
|
if (preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER)) {
|
||||||
foreach ($matches as $match) {
|
foreach ($matches as $match) {
|
||||||
$indexName = str_replace('`', '', $match[1]);
|
$indexName = $match[1];
|
||||||
$indexColumns = array_map('trim', explode(',', str_replace('`', '', $match[2])));
|
$indexColumns = array_map('trim', explode('`,`', trim($match[2], '`')));
|
||||||
$uniqueIndexes[$indexName] = $indexColumns;
|
$uniqueIndexes[$indexName] = $indexColumns;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -531,6 +531,16 @@ abstract class SchemaTest extends DatabaseTestCase
|
|||||||
'somecolUnique' => ['somecol'],
|
'somecolUnique' => ['somecol'],
|
||||||
'someCol2Unique' => ['someCol2'],
|
'someCol2Unique' => ['someCol2'],
|
||||||
], $uniqueIndexes);
|
], $uniqueIndexes);
|
||||||
|
|
||||||
|
// see https://github.com/yiisoft/yii2/issues/13814
|
||||||
|
$db->createCommand()->createIndex('another unique index', 'uniqueIndex', 'someCol2', true)->execute();
|
||||||
|
|
||||||
|
$uniqueIndexes = $schema->findUniqueIndexes($schema->getTableSchema('uniqueIndex', true));
|
||||||
|
$this->assertEquals([
|
||||||
|
'somecolUnique' => ['somecol'],
|
||||||
|
'someCol2Unique' => ['someCol2'],
|
||||||
|
'another unique index' => ['someCol2'],
|
||||||
|
], $uniqueIndexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testContraintTablesExistance()
|
public function testContraintTablesExistance()
|
||||||
|
|||||||
Reference in New Issue
Block a user