From 3615134d3dc456d825635c505a89fc09a5ba2479 Mon Sep 17 00:00:00 2001 From: "bobonog@gmail.com" Date: Wed, 5 Jul 2023 11:50:57 +0200 Subject: [PATCH 01/13] Added method for addCheck() and dropCheck(), resolve #19817 --- framework/db/Migration.php | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/framework/db/Migration.php b/framework/db/Migration.php index 975898cd53f..433d97d14fc 100644 --- a/framework/db/Migration.php +++ b/framework/db/Migration.php @@ -311,7 +311,7 @@ public function delete($table, $condition = '', $params = []) * * If a column is specified with definition only (e.g. 'PRIMARY KEY (name, type)'), it will be directly * put into the generated SQL. - * + * * Example usage: * ```php * class m200000_000000_create_table_fruits extends \yii\db\Migration @@ -319,7 +319,7 @@ public function delete($table, $condition = '', $params = []) * public function safeUp() * { * $this->createTable('{{%fruits}}', [ - * // ... + * // ... * 'column_name double precision null default null', * ``` @@ -519,6 +519,35 @@ public function dropIndex($name, $table) $this->endCommand($time); } + /** + * Creates a SQL command for adding a check constraint to an existing table. + * @param string $name the name of the check constraint. + * The name will be properly quoted by the method. + * @param string $table the table that the check constraint will be added to. + * The name will be properly quoted by the method. + * @param string $expression the SQL of the `CHECK` constraint. + */ + public function addCheck($name, $table, $expression) + { + $time = $this->beginCommand("add check $name in table $table"); + $this->db->createCommand()->addCheck($name, $table, $expression)->execute(); + $this->endCommand($time); + } + + /** + * Creates a SQL command for dropping a check constraint. + * @param string $name the name of the check constraint to be dropped. + * The name will be properly quoted by the method. + * @param string $table the table whose check constraint is to be dropped. + * The name will be properly quoted by the method. + */ + public function dropCheck($name, $table) + { + $time = $this->beginCommand("add check $name in table $table"); + $this->db->createCommand()->dropCheck($name, $table)->execute(); + $this->endCommand($time); + } + /** * Builds and execute a SQL statement for adding comment to column. * From d94fd0f56cc3d78ac0c278eb6a57d8189a9d918d Mon Sep 17 00:00:00 2001 From: "bobonog@gmail.com" Date: Wed, 5 Jul 2023 11:54:24 +0200 Subject: [PATCH 02/13] Removed (for Mysql QueryBuilder) NotSupportedException() when executing addheck() and dropCheck(), resolve #19819 --- framework/db/mysql/QueryBuilder.php | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/framework/db/mysql/QueryBuilder.php b/framework/db/mysql/QueryBuilder.php index fc10931c7a1..2cc1b1c2ae5 100644 --- a/framework/db/mysql/QueryBuilder.php +++ b/framework/db/mysql/QueryBuilder.php @@ -150,24 +150,6 @@ public function dropUnique($name, $table) return $this->dropIndex($name, $table); } - /** - * {@inheritdoc} - * @throws NotSupportedException this is not supported by MySQL. - */ - public function addCheck($name, $table, $expression) - { - throw new NotSupportedException(__METHOD__ . ' is not supported by MySQL.'); - } - - /** - * {@inheritdoc} - * @throws NotSupportedException this is not supported by MySQL. - */ - public function dropCheck($name, $table) - { - throw new NotSupportedException(__METHOD__ . ' is not supported by MySQL.'); - } - /** * Creates a SQL statement for resetting the sequence value of a table's primary key. * The sequence will be reset such that the primary key of the next new row inserted @@ -266,7 +248,7 @@ protected function prepareInsertValues($table, $columns, $params = []) $columns = [reset($tableSchema->columns)->name]; $defaultValue = 'DEFAULT'; } - + foreach ($columns as $name) { $names[] = $this->db->quoteColumnName($name); $placeholders[] = $defaultValue; From 8aa0ac69a64d5dd115777e978ca033b25fe8acf0 Mon Sep 17 00:00:00 2001 From: Roberto Braga Date: Fri, 22 Sep 2023 09:03:50 +0200 Subject: [PATCH 03/13] Correction on dropCheck() message --- framework/db/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/db/Migration.php b/framework/db/Migration.php index 433d97d14fc..3f8c4ca73db 100644 --- a/framework/db/Migration.php +++ b/framework/db/Migration.php @@ -558,7 +558,7 @@ public function dropCheck($name, $table) */ public function addCommentOnColumn($table, $column, $comment) { - $time = $this->beginCommand("add comment on column $column"); + $time = $this->beginCommand("drop comment on column $column"); $this->db->createCommand()->addCommentOnColumn($table, $column, $comment)->execute(); $this->endCommand($time); } From 493cbc3577daded92528ed563da52f8ea43fc5a9 Mon Sep 17 00:00:00 2001 From: Roberto Braga Date: Fri, 22 Sep 2023 09:05:32 +0200 Subject: [PATCH 04/13] Correction on dropCheck() message --- framework/db/Migration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/db/Migration.php b/framework/db/Migration.php index 3f8c4ca73db..cae68ef042f 100644 --- a/framework/db/Migration.php +++ b/framework/db/Migration.php @@ -543,7 +543,7 @@ public function addCheck($name, $table, $expression) */ public function dropCheck($name, $table) { - $time = $this->beginCommand("add check $name in table $table"); + $time = $this->beginCommand("drop check $name in table $table"); $this->db->createCommand()->dropCheck($name, $table)->execute(); $this->endCommand($time); } From d7fa8aaa6b77f0710a32f86d386cea7e2833da71 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Fri, 17 May 2024 09:57:55 -0400 Subject: [PATCH 05/13] Add line in `CHANGELOG..md`. --- framework/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 302698ff536..3ed104d15db 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -27,6 +27,7 @@ Yii Framework 2 Change Log - New #20137: Added `yii\caching\CallbackDependency` to allow using a callback to determine if a cache dependency is still valid (laxity7) - Enh #20134: Raise minimum `PHP` version to `7.3` (@terabytesoftw) - Bug #20141: Update `ezyang/htmlpurifier` dependency to version `4.17` (@terabytesoftw) +- Bug #19817, #19819 Add MySQL Query `addCheck()` and `dropCheck()` (@bobonov) 2.0.49.2 October 12, 2023 ------------------------- From bd68552b73612c586386f704ae9b6c891e13da79 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Fri, 17 May 2024 10:01:31 -0400 Subject: [PATCH 06/13] Fix error typo. --- framework/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 3ed104d15db..43c56c52296 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -27,7 +27,7 @@ Yii Framework 2 Change Log - New #20137: Added `yii\caching\CallbackDependency` to allow using a callback to determine if a cache dependency is still valid (laxity7) - Enh #20134: Raise minimum `PHP` version to `7.3` (@terabytesoftw) - Bug #20141: Update `ezyang/htmlpurifier` dependency to version `4.17` (@terabytesoftw) -- Bug #19817, #19819 Add MySQL Query `addCheck()` and `dropCheck()` (@bobonov) +- Bug #19817: Add MySQL Query `addCheck()` and `dropCheck()` (@bobonov) 2.0.49.2 October 12, 2023 ------------------------- From f3f2f2bb0836944a050f0343e1f0adb02ec6efc6 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sat, 18 May 2024 11:43:02 -0400 Subject: [PATCH 07/13] Apply sugestion rob006. --- framework/db/Migration.php | 2 +- tests/framework/db/mysql/CommandTest.php | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/framework/db/Migration.php b/framework/db/Migration.php index 95a7c07da0d..a36f0d41697 100644 --- a/framework/db/Migration.php +++ b/framework/db/Migration.php @@ -559,7 +559,7 @@ public function dropCheck($name, $table) */ public function addCommentOnColumn($table, $column, $comment) { - $time = $this->beginCommand("drop comment on column $column"); + $time = $this->beginCommand("add comment on column $column"); $this->db->createCommand()->addCommentOnColumn($table, $column, $comment)->execute(); $this->endCommand($time); } diff --git a/tests/framework/db/mysql/CommandTest.php b/tests/framework/db/mysql/CommandTest.php index 0cd6e63aabf..e80bb4b1fdb 100644 --- a/tests/framework/db/mysql/CommandTest.php +++ b/tests/framework/db/mysql/CommandTest.php @@ -16,9 +16,4 @@ class CommandTest extends \yiiunit\framework\db\CommandTest public $driverName = 'mysql'; protected $upsertTestCharCast = 'CONVERT([[address]], CHAR)'; - - public function testAddDropCheck() - { - $this->markTestSkipped('MySQL does not support adding/dropping check constraints.'); - } } From 4996fd3d913c9b3b9723b56b007afb2cfd48638a Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sat, 18 May 2024 13:35:03 -0400 Subject: [PATCH 08/13] Add draft `loadTableChecks()` method, and add tests. --- framework/db/mysql/Schema.php | 48 ++++++++++++++++++- tests/framework/db/CommandTest.php | 4 +- tests/framework/db/mysql/CommandTest.php | 44 +++++++++++++++++ tests/framework/db/mysql/QueryBuilderTest.php | 7 +-- 4 files changed, 93 insertions(+), 10 deletions(-) diff --git a/framework/db/mysql/Schema.php b/framework/db/mysql/Schema.php index 6f8a2eb3ef7..50da4699c05 100644 --- a/framework/db/mysql/Schema.php +++ b/framework/db/mysql/Schema.php @@ -11,6 +11,7 @@ use Yii; use yii\base\InvalidConfigException; use yii\base\NotSupportedException; +use yii\db\CheckConstraint; use yii\db\Constraint; use yii\db\ConstraintFinderInterface; use yii\db\ConstraintFinderTrait; @@ -201,11 +202,54 @@ protected function loadTableUniques($tableName) /** * {@inheritdoc} - * @throws NotSupportedException if this method is called. */ protected function loadTableChecks($tableName) { - throw new NotSupportedException('MySQL does not support check constraints.'); + // check version MySQL >= 8.0.16 + if (version_compare($this->db->getSlavePdo()->getAttribute(\PDO::ATTR_SERVER_VERSION), '8.0.16', '<')) { + $this->markTestSkipped('MySQL < 8.0.16 does not support CHECK constraints.'); + } + + $checks = []; + + $sql = <<resolveTableName($tableName); + $tableRows = $this->db->createCommand($sql, [':tableName' => $resolvedName->name])->queryAll(); + + if ($tableRows === []) { + return $checks; + } + + foreach ($tableRows as $tableRow) { + $sql = <<db->createCommand($sql, [':constraintName' => $tableRow['CONSTRAINT_NAME']])->queryAll(); + + 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; + } + } + + return $checks; } /** diff --git a/tests/framework/db/CommandTest.php b/tests/framework/db/CommandTest.php index b888a7073d6..65159a2f4e4 100644 --- a/tests/framework/db/CommandTest.php +++ b/tests/framework/db/CommandTest.php @@ -619,7 +619,7 @@ public function invalidSelectColumns() * Test INSERT INTO ... SELECT SQL statement with wrong query object. * * @dataProvider invalidSelectColumns - * + * * @param mixed $invalidSelectColumns */ public function testInsertSelectFailed($invalidSelectColumns) @@ -1208,7 +1208,6 @@ public function testAddDropCheck() $db = $this->getConnection(false); $tableName = 'test_ck'; $name = 'test_ck_constraint'; - /** @var \yii\db\pgsql\Schema $schema */ $schema = $db->getSchema(); if ($schema->getTableSchema($tableName) !== null) { @@ -1226,6 +1225,7 @@ public function testAddDropCheck() ); $db->createCommand()->dropCheck($name, $tableName)->execute(); + $this->assertEmpty($schema->getTableChecks($tableName, true)); } diff --git a/tests/framework/db/mysql/CommandTest.php b/tests/framework/db/mysql/CommandTest.php index e80bb4b1fdb..b8fae85dc70 100644 --- a/tests/framework/db/mysql/CommandTest.php +++ b/tests/framework/db/mysql/CommandTest.php @@ -16,4 +16,48 @@ class CommandTest extends \yiiunit\framework\db\CommandTest public $driverName = 'mysql'; protected $upsertTestCharCast = 'CONVERT([[address]], CHAR)'; + + public function testAddDropCheckSeveral() + { + $db = $this->getConnection(false); + $tableName = 'test_ck_several'; + $schema = $db->getSchema(); + + if ($schema->getTableSchema($tableName) !== null) { + $db->createCommand()->dropTable($tableName)->execute(); + } + $db->createCommand()->createTable($tableName, [ + 'int1' => 'integer', + 'int2' => 'integer', + 'int3' => 'integer', + ])->execute(); + + $this->assertEmpty($schema->getTableChecks($tableName, true)); + + $constraints = [ + ['name' => 'check_int1_positive', 'expression' => '[[int1]] > 0', 'expected' => '(`int1` > 0)'], + ['name' => 'check_int2_nonzero', 'expression' => '[[int2]] <> 0', 'expected' => '(`int2` <> 0)'], + ['name' => 'check_int3_less_than_100', 'expression' => '[[int3]] < 100', 'expected' => '(`int3` < 100)'], + ]; + + foreach ($constraints as $constraint) { + $db->createCommand()->addCheck($constraint['name'], $tableName, $constraint['expression'])->execute(); + } + + $tableChecks = $schema->getTableChecks($tableName, true); + $this->assertCount(3, $tableChecks); + + foreach ($constraints as $index => $constraint) { + $this->assertSame( + $constraints[$index]['expected'], + $tableChecks[$index]->expression + ); + } + + foreach ($constraints as $constraint) { + $db->createCommand()->dropCheck($constraint['name'], $tableName)->execute(); + } + + $this->assertEmpty($schema->getTableChecks($tableName, true)); + } } diff --git a/tests/framework/db/mysql/QueryBuilderTest.php b/tests/framework/db/mysql/QueryBuilderTest.php index 659bf1a9ee2..f0f8cdfb397 100644 --- a/tests/framework/db/mysql/QueryBuilderTest.php +++ b/tests/framework/db/mysql/QueryBuilderTest.php @@ -196,11 +196,6 @@ public function uniquesProvider() return $result; } - public function checksProvider() - { - $this->markTestSkipped('Adding/dropping check constraints is not supported in MySQL.'); - } - public function defaultValuesProvider() { $this->markTestSkipped('Adding/dropping default constraints is not supported in MySQL.'); @@ -403,7 +398,7 @@ public function testDefaultValues() // primary key columns should have NULL as value $sql = $command->insert('null_values', [])->getRawSql(); $this->assertEquals("INSERT INTO `null_values` (`id`) VALUES (NULL)", $sql); - + // non-primary key columns should have DEFAULT as value $sql = $command->insert('negative_default_values', [])->getRawSql(); $this->assertEquals("INSERT INTO `negative_default_values` (`tinyint_col`) VALUES (DEFAULT)", $sql); From bd73df5dcf68a6425dcfe381b235e311396b58ee Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sat, 18 May 2024 13:39:02 -0400 Subject: [PATCH 09/13] Fix MySQL version check for check constraints. --- framework/db/mysql/Schema.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/db/mysql/Schema.php b/framework/db/mysql/Schema.php index 50da4699c05..21cca273ab1 100644 --- a/framework/db/mysql/Schema.php +++ b/framework/db/mysql/Schema.php @@ -207,7 +207,7 @@ protected function loadTableChecks($tableName) { // check version MySQL >= 8.0.16 if (version_compare($this->db->getSlavePdo()->getAttribute(\PDO::ATTR_SERVER_VERSION), '8.0.16', '<')) { - $this->markTestSkipped('MySQL < 8.0.16 does not support CHECK constraints.'); + throw new NotSupportedException('MySQL < 8.0.16 does not support check constraints.'); } $checks = []; From 132b06cf8d2bb04379d8d46dee010916ca1ed9a8 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sat, 18 May 2024 13:48:44 -0400 Subject: [PATCH 10/13] Run tests MySQL > `8.0.16`. --- tests/framework/db/CommandTest.php | 5 +++++ tests/framework/db/mysql/CommandTest.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/tests/framework/db/CommandTest.php b/tests/framework/db/CommandTest.php index 65159a2f4e4..cd3ecc6d686 100644 --- a/tests/framework/db/CommandTest.php +++ b/tests/framework/db/CommandTest.php @@ -1206,6 +1206,11 @@ public function testAddDropUnique() public function testAddDropCheck() { $db = $this->getConnection(false); + + if (version_compare($db->getServerVersion(), '8.0.16', '<')) { + $this->markTestSkipped('MySQL < 8.0.16 does not support CHECK constraints.'); + } + $tableName = 'test_ck'; $name = 'test_ck_constraint'; $schema = $db->getSchema(); diff --git a/tests/framework/db/mysql/CommandTest.php b/tests/framework/db/mysql/CommandTest.php index b8fae85dc70..60c562c737b 100644 --- a/tests/framework/db/mysql/CommandTest.php +++ b/tests/framework/db/mysql/CommandTest.php @@ -20,6 +20,11 @@ class CommandTest extends \yiiunit\framework\db\CommandTest public function testAddDropCheckSeveral() { $db = $this->getConnection(false); + + if (version_compare($db->getServerVersion(), '8.0.16', '<')) { + $this->markTestSkipped('MySQL < 8.0.16 does not support CHECK constraints.'); + } + $tableName = 'test_ck_several'; $schema = $db->getSchema(); From 14e2631fdf76de2d9149db5b80e0d41bdb3dcdda Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sat, 18 May 2024 14:03:39 -0400 Subject: [PATCH 11/13] Normalize column names. --- framework/db/mysql/Schema.php | 15 +++++++++++---- tests/framework/db/mysql/SchemaTest.php | 4 ---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/framework/db/mysql/Schema.php b/framework/db/mysql/Schema.php index 21cca273ab1..bcf11142e88 100644 --- a/framework/db/mysql/Schema.php +++ b/framework/db/mysql/Schema.php @@ -223,26 +223,33 @@ protected function loadTableChecks($tableName) return $checks; } + $tableRows = $this->normalizePdoRowKeyCase($tableRows, true); + foreach ($tableRows as $tableRow) { $sql = <<db->createCommand($sql, [':constraintName' => $tableRow['CONSTRAINT_NAME']])->queryAll(); + $checkRows = $this->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)) { + if (preg_match('/\(`?([a-zA-Z0-9_]+)`?\s*[><=]/', $checkRow['check_clause'], $matches)) { $columnName = $matches[1]; } $check = new CheckConstraint( [ - 'name' => $checkRow['CONSTRAINT_NAME'], + 'name' => $checkRow['constraint_name'], 'columnNames' => $columnName, - 'expression' => $checkRow['CHECK_CLAUSE'], + 'expression' => $checkRow['check_clause'], ] ); $checks[] = $check; diff --git a/tests/framework/db/mysql/SchemaTest.php b/tests/framework/db/mysql/SchemaTest.php index 43a66a60b57..9c2ca835078 100644 --- a/tests/framework/db/mysql/SchemaTest.php +++ b/tests/framework/db/mysql/SchemaTest.php @@ -77,16 +77,12 @@ public function testGetSchemaNames() public function constraintsProvider() { $result = parent::constraintsProvider(); - $result['1: check'][2] = false; $result['2: primary key'][2]->name = null; - $result['2: check'][2] = false; // Work aroung bug in MySQL 5.1 - it creates only this table in lowercase. O_o $result['3: foreign key'][2][0]->foreignTableName = new AnyCaseValue('T_constraints_2'); - $result['3: check'][2] = false; - $result['4: check'][2] = false; return $result; } From 2d2e141e3e11bd51ca5ddc864440cef3a7abb3fb Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sat, 18 May 2024 16:54:18 -0400 Subject: [PATCH 12/13] Minor improvents. --- framework/db/mysql/Schema.php | 45 ++++++++++--------------- tests/framework/db/SchemaTest.php | 21 ++++++++++++ tests/framework/db/mysql/SchemaTest.php | 2 ++ 3 files changed, 41 insertions(+), 27 deletions(-) diff --git a/framework/db/mysql/Schema.php b/framework/db/mysql/Schema.php index bcf11142e88..7a60c620f21 100644 --- a/framework/db/mysql/Schema.php +++ b/framework/db/mysql/Schema.php @@ -213,7 +213,11 @@ protected function loadTableChecks($tableName) $checks = []; $sql = <<resolveTableName($tableName); @@ -226,34 +230,21 @@ protected function loadTableChecks($tableName) $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 480aabbfdd0..fcc3036d8a1 100644 --- a/tests/framework/db/SchemaTest.php +++ b/tests/framework/db/SchemaTest.php @@ -773,6 +773,13 @@ public function testTableSchemaConstraints($tableName, $type, $expected) $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 @@ public function testTableSchemaConstraintsWithPdoUppercase($tableName, $type, $e $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 @@ public function testTableSchemaConstraintsWithPdoLowercase($tableName, $type, $e $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 9c2ca835078..ba98f45e385 100644 --- a/tests/framework/db/mysql/SchemaTest.php +++ b/tests/framework/db/mysql/SchemaTest.php @@ -78,6 +78,8 @@ public function constraintsProvider() { $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 From 2ead4f31c6b64abe8535737ee4919f72ecb55a68 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Sat, 18 May 2024 17:01:35 -0400 Subject: [PATCH 13/13] Fixed tests. --- tests/framework/db/SchemaTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/framework/db/SchemaTest.php b/tests/framework/db/SchemaTest.php index fcc3036d8a1..4dfa40b915c 100644 --- a/tests/framework/db/SchemaTest.php +++ b/tests/framework/db/SchemaTest.php @@ -774,6 +774,7 @@ public function testTableSchemaConstraints($tableName, $type, $expected) } if ( + $this->driverName === 'mysql' && version_compare($this->getConnection(false)->getServerVersion(), '8.0.16', '<') && $type === 'checks' ) { @@ -797,6 +798,7 @@ public function testTableSchemaConstraintsWithPdoUppercase($tableName, $type, $e } if ( + $this->driverName === 'mysql' && version_compare($this->getConnection(false)->getServerVersion(), '8.0.16', '<') && $type === 'checks' ) { @@ -822,6 +824,7 @@ public function testTableSchemaConstraintsWithPdoLowercase($tableName, $type, $e } if ( + $this->driverName === 'mysql' && version_compare($this->getConnection(false)->getServerVersion(), '8.0.16', '<') && $type === 'checks' ) {