1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\DBAL\Functional\Ticket; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Schema\Comparator; |
6
|
|
|
use Doctrine\DBAL\Schema\Table; |
7
|
|
|
use Doctrine\Tests\DbalFunctionalTestCase; |
8
|
|
|
|
9
|
|
|
final class DBAL2807Test extends DbalFunctionalTestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* {@inheritDoc} |
13
|
|
|
*/ |
14
|
|
|
public function setUp() |
15
|
|
|
{ |
16
|
|
|
parent::setUp(); |
17
|
|
|
|
18
|
|
|
if (!in_array($this->getPlatform()->getName(), ['mysql'])) |
19
|
|
|
{ |
20
|
|
|
$this->markTestSkipped('Restricted to MySQL.'); |
21
|
|
|
|
22
|
|
|
return; |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Ensures that the primary key is created within the same "alter table" statement that an auto-increment column |
28
|
|
|
* is added to the table as part of the new primary key. |
29
|
|
|
* |
30
|
|
|
* Before the fix for this problem this resulted in a database error: |
31
|
|
|
* 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 |
32
|
|
|
*/ |
33
|
|
|
public function testAlterPrimaryKeyToAutoIncrementColumn() |
34
|
|
|
{ |
35
|
|
|
$table = new Table('my_table'); |
36
|
|
|
$table->addColumn('initial_id', 'integer'); |
37
|
|
|
$table->setPrimaryKey(['initial_id']); |
38
|
|
|
|
39
|
|
|
$newTable = clone $table; |
40
|
|
|
$newTable->addColumn('new_id', 'integer', ['autoincrement' => true]); |
41
|
|
|
$newTable->dropPrimaryKey(); |
42
|
|
|
$newTable->setPrimaryKey(['new_id']); |
43
|
|
|
|
44
|
|
|
$diff = (new Comparator())->diffTable($table, $newTable); |
45
|
|
|
|
46
|
|
|
$this->assertSame( |
47
|
|
|
['ALTER TABLE my_table ADD new_id INT AUTO_INCREMENT NOT NULL, DROP PRIMARY KEY, ADD PRIMARY KEY (new_id)',], |
48
|
|
|
$this->getPlatform()->getAlterTableSQL($diff) |
|
|
|
|
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function getPlatform() |
53
|
|
|
{ |
54
|
|
|
return $this->connection->getDatabasePlatform(); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|