diff --git a/framework/db/mysql/Schema.php b/framework/db/mysql/Schema.php index bcf11142e8..7a60c620f2 100644 --- a/framework/db/mysql/Schema.php +++ b/framework/db/mysql/Schema.php @@ -213,7 +213,11 @@ SQL; $checks = []; $sql = <<resolveTableName($tableName); @@ -226,34 +230,21 @@ SQL; $tableRows = $this->normalizePdoRowKeyCase($tableRows, true); foreach ($tableRows as $tableRow) { - $sql = <<db->createCommand( - $sql, - [':constraintName' => $tableRow['constraint_name']], - )->queryAll(); - - $checkRows = $this->normalizePdoRowKeyCase($checkRows, true); - - foreach ($checkRows as $checkRow) { - $matches = []; - $columnName = null; - - if (preg_match('/\(`?([a-zA-Z0-9_]+)`?\s*[><=]/', $checkRow['check_clause'], $matches)) { - $columnName = $matches[1]; - } - - $check = new CheckConstraint( - [ - 'name' => $checkRow['constraint_name'], - 'columnNames' => $columnName, - 'expression' => $checkRow['check_clause'], - ] - ); - $checks[] = $check; + if (preg_match('/\(`?([a-zA-Z0-9_]+)`?\s*[><=]/', $tableRow['check_clause'], $matches)) { + $columnName = $matches[1]; } + + $check = new CheckConstraint( + [ + 'name' => $tableRow['constraint_name'], + 'columnNames' => [$columnName], + 'expression' => $tableRow['check_clause'], + ] + ); + $checks[] = $check; } return $checks; diff --git a/tests/framework/db/SchemaTest.php b/tests/framework/db/SchemaTest.php index 480aabbfdd..fcc3036d8a 100644 --- a/tests/framework/db/SchemaTest.php +++ b/tests/framework/db/SchemaTest.php @@ -773,6 +773,13 @@ abstract class SchemaTest extends DatabaseTestCase $this->expectException('yii\base\NotSupportedException'); } + if ( + version_compare($this->getConnection(false)->getServerVersion(), '8.0.16', '<') && + $type === 'checks' + ) { + $this->expectException('yii\base\NotSupportedException'); + } + $constraints = $this->getConnection(false)->getSchema()->{'getTable' . ucfirst($type)}($tableName); $this->assertMetadataEquals($expected, $constraints); } @@ -789,6 +796,13 @@ abstract class SchemaTest extends DatabaseTestCase $this->expectException('yii\base\NotSupportedException'); } + if ( + version_compare($this->getConnection(false)->getServerVersion(), '8.0.16', '<') && + $type === 'checks' + ) { + $this->expectException('yii\base\NotSupportedException'); + } + $connection = $this->getConnection(false); $connection->getSlavePdo(true)->setAttribute(PDO::ATTR_CASE, PDO::CASE_UPPER); $constraints = $connection->getSchema()->{'getTable' . ucfirst($type)}($tableName, true); @@ -807,6 +821,13 @@ abstract class SchemaTest extends DatabaseTestCase $this->expectException('yii\base\NotSupportedException'); } + if ( + version_compare($this->getConnection(false)->getServerVersion(), '8.0.16', '<') && + $type === 'checks' + ) { + $this->expectException('yii\base\NotSupportedException'); + } + $connection = $this->getConnection(false); $connection->getSlavePdo(true)->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); $constraints = $connection->getSchema()->{'getTable' . ucfirst($type)}($tableName, true); diff --git a/tests/framework/db/mysql/SchemaTest.php b/tests/framework/db/mysql/SchemaTest.php index 9c2ca83507..ba98f45e38 100644 --- a/tests/framework/db/mysql/SchemaTest.php +++ b/tests/framework/db/mysql/SchemaTest.php @@ -78,6 +78,8 @@ SQL; { $result = parent::constraintsProvider(); + $result['1: check'][2][0]->expression = "(`C_check` <> _utf8mb4\\'\\')"; + $result['2: primary key'][2]->name = null; // Work aroung bug in MySQL 5.1 - it creates only this table in lowercase. O_o