diff --git a/.github/ISSUE_TEMPLATE/BC_Break.md b/.github/ISSUE_TEMPLATE/BC_Break.md index fe2f6eac490..c372e7fefd5 100644 --- a/.github/ISSUE_TEMPLATE/BC_Break.md +++ b/.github/ISSUE_TEMPLATE/BC_Break.md @@ -1,6 +1,6 @@ --- name: 💥 BC Break -about: Have you encountered an issue during upgrade? 💣 +about: Have you encountered an issue during an upgrade? 💣 --- + -#### Previous behavior +#### Previous behaviour - + #### Current behavior - + #### How to reproduce diff --git a/.github/ISSUE_TEMPLATE/Bug.md b/.github/ISSUE_TEMPLATE/Bug.md index b0767e8c790..466769fc7a2 100644 --- a/.github/ISSUE_TEMPLATE/Bug.md +++ b/.github/ISSUE_TEMPLATE/Bug.md @@ -14,11 +14,11 @@ about: Something is broken? 🔨 #### Summary - + #### Current behavior - + #### How to reproduce @@ -28,7 +28,7 @@ If possible, also add a code snippet with relevant configuration, driver/platfor Adding a failing Unit or Functional Test would help us a lot - you can submit one in a Pull Request separately, referencing this bug report. --> -#### Expected behavior +#### Expected behaviour - + diff --git a/.github/ISSUE_TEMPLATE/Support_Question.md b/.github/ISSUE_TEMPLATE/Support_Question.md index 59a63fda112..d5bccbd15fa 100644 --- a/.github/ISSUE_TEMPLATE/Support_Question.md +++ b/.github/ISSUE_TEMPLATE/Support_Question.md @@ -10,7 +10,7 @@ about: Have a problem that you can't figure out? 🤔 | Version | x.y.z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 332d6db0bb8..d88b155d0a0 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -8,4 +8,4 @@ #### Summary - + diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index a16bfe79da0..e255c2ae244 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -622,6 +622,18 @@ public function getAlterTableSQL(TableDiff $diff) $queryParts[] = 'ADD PRIMARY KEY (' . implode(', ', $keyColumns) . ')'; unset($diff->addedIndexes['primary']); } + // Necessary in case the new primary key includes a new auto_increment column + elseif (isset($diff->changedIndexes['primary'])) { + foreach ($diff->changedIndexes['primary']->getColumns() as $columnName) { + if (isset($diff->addedColumns[$columnName]) && $diff->addedColumns[$columnName]->getAutoincrement()) { + $keyColumns = array_unique(array_values($diff->changedIndexes['primary']->getColumns())); + $queryParts[] = 'DROP PRIMARY KEY'; + $queryParts[] = 'ADD PRIMARY KEY (' . implode(', ', $keyColumns) . ')'; + unset($diff->changedIndexes['primary']); + break; + } + } + } $sql = []; $tableSql = []; diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index e635af754d9..c24607f0e83 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -51,7 +51,7 @@ class SQLParserUtils const ESCAPED_SINGLE_QUOTED_TEXT = "(?:'(?:\\\\\\\\)+'|'(?:[^'\\\\]|\\\\'?|'')*')"; const ESCAPED_DOUBLE_QUOTED_TEXT = '(?:"(?:\\\\\\\\)+"|"(?:[^"\\\\]|\\\\"?)*")'; const ESCAPED_BACKTICK_QUOTED_TEXT = '(?:`(?:\\\\\\\\)+`|`(?:[^`\\\\]|\\\\`?)*`)'; - const ESCAPED_BRACKET_QUOTED_TEXT = '(?_setName($name); - $this->allocationSize = is_numeric($allocationSize) ? $allocationSize : 1; - $this->initialValue = is_numeric($initialValue) ? $initialValue : 1; + $this->setAllocationSize($allocationSize); + $this->setInitialValue($initialValue); $this->cache = $cache; } @@ -93,7 +93,7 @@ public function getCache() */ public function setAllocationSize($allocationSize) { - $this->allocationSize = is_numeric($allocationSize) ? $allocationSize : 1; + $this->allocationSize = is_numeric($allocationSize) ? (int) $allocationSize : 1; return $this; } @@ -105,7 +105,7 @@ public function setAllocationSize($allocationSize) */ public function setInitialValue($initialValue) { - $this->initialValue = is_numeric($initialValue) ? $initialValue : 1; + $this->initialValue = is_numeric($initialValue) ? (int) $initialValue : 1; return $this; } diff --git a/lib/Doctrine/DBAL/Version.php b/lib/Doctrine/DBAL/Version.php index 5f22681e56a..47f82deb390 100644 --- a/lib/Doctrine/DBAL/Version.php +++ b/lib/Doctrine/DBAL/Version.php @@ -38,7 +38,7 @@ class Version /** * Current Doctrine Version. */ - public const VERSION = '2.8.0-DEV'; + public const VERSION = '2.8.1-DEV'; /** * Compares a Doctrine version with the current one. diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL2807Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL2807Test.php new file mode 100644 index 00000000000..62150818a4c --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL2807Test.php @@ -0,0 +1,56 @@ +getPlatform()->getName(), ['mysql'])) + { + $this->markTestSkipped('Restricted to MySQL.'); + + return; + } + } + + /** + * Ensures that the primary key is created within the same "alter table" statement that an auto-increment column + * is added to the table as part of the new primary key. + * + * Before the fix for this problem this resulted in a database error: + * SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key + */ + public function testAlterPrimaryKeyToAutoIncrementColumn() + { + $table = new Table('my_table'); + $table->addColumn('initial_id', 'integer'); + $table->setPrimaryKey(['initial_id']); + + $newTable = clone $table; + $newTable->addColumn('new_id', 'integer', ['autoincrement' => true]); + $newTable->dropPrimaryKey(); + $newTable->setPrimaryKey(['new_id']); + + $diff = (new Comparator())->diffTable($table, $newTable); + + $this->assertSame( + ['ALTER TABLE my_table ADD new_id INT AUTO_INCREMENT NOT NULL, DROP PRIMARY KEY, ADD PRIMARY KEY (new_id)',], + $this->getPlatform()->getAlterTableSQL($diff) + ); + } + + protected function getPlatform() + { + return $this->_conn->getDatabasePlatform(); + } +} diff --git a/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php b/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php index a75112ec847..0e057953b8a 100644 --- a/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php +++ b/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php @@ -55,7 +55,8 @@ public function dataGetPlaceholderPositions() array('SELECT foo::date as date FROM Foo WHERE bar > :start_date AND baz > :start_date', false, array(46 => 'start_date', 68 => 'start_date')), // Ticket GH-259 array('SELECT `d.ns:col_name` FROM my_table d WHERE `d.date` >= :param1', false, array(57 => 'param1')), // Ticket DBAL-552 array('SELECT [d.ns:col_name] FROM my_table d WHERE [d.date] >= :param1', false, array(57 => 'param1')), // Ticket DBAL-552 - array('SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[:foo])', false, array(56 => 'foo')), // Ticket GH-2295 + ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[:foo])', false, [56 => 'foo']], // Ticket GH-2295 + ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, array[:foo])', false, [56 => 'foo']], array( <<<'SQLDATA' SELECT * FROM foo WHERE diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index 40250020023..24d097c3006 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -435,11 +435,13 @@ public function testCompareSequences() $seq1 = new Sequence('foo', 1, 1); $seq2 = new Sequence('foo', 1, 2); $seq3 = new Sequence('foo', 2, 1); + $seq4 = new Sequence('foo', '1', '1'); $c = new Comparator(); self::assertTrue($c->diffSequence($seq1, $seq2)); self::assertTrue($c->diffSequence($seq1, $seq3)); + self::assertFalse($c->diffSequence($seq1, $seq4)); } public function testRemovedSequence()