1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace Doctrine\Tests\DBAL\Schema\Platforms;
use Doctrine\DBAL\Schema\Table;
class MySQLSchemaTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Comparator
*/
private $comparator;
/**
*
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
private $platform;
protected function setUp()
{
$this->comparator = new \Doctrine\DBAL\Schema\Comparator;
$this->platform = new \Doctrine\DBAL\Platforms\MySqlPlatform;
}
public function testSwitchPrimaryKeyOrder()
{
$tableOld = new Table("test");
$tableOld->addColumn('foo_id', 'integer');
$tableOld->addColumn('bar_id', 'integer');
$tableNew = clone $tableOld;
$tableOld->setPrimaryKey(array('foo_id', 'bar_id'));
$tableNew->setPrimaryKey(array('bar_id', 'foo_id'));
$diff = $this->comparator->diffTable($tableOld, $tableNew);
$sql = $this->platform->getAlterTableSQL($diff);
$this->assertEquals(
array(
'ALTER TABLE test DROP PRIMARY KEY',
'ALTER TABLE test ADD PRIMARY KEY (bar_id, foo_id)'
), $sql
);
}
/**
* @group DBAL-132
*/
public function testGenerateForeignKeySQL()
{
$tableOld = new Table("test");
$tableOld->addColumn('foo_id', 'integer');
$tableOld->addUnnamedForeignKeyConstraint('test_foreign', array('foo_id'), array('foo_id'));
$sqls = array();
foreach ($tableOld->getForeignKeys() as $fk) {
$sqls[] = $this->platform->getCreateForeignKeySQL($fk, $tableOld);
}
$this->assertEquals(array("ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C8E48560F FOREIGN KEY (foo_id) REFERENCES test_foreign (foo_id)"), $sqls);
}
/**
* @group DDC-1737
*/
public function testClobNoAlterTable()
{
$tableOld = new Table("test");
$tableOld->addColumn('id', 'integer');
$tableOld->addColumn('description', 'string', array('length' => 65536));
$tableNew = clone $tableOld;
$tableNew->setPrimaryKey(array('id'));
$diff = $this->comparator->diffTable($tableOld, $tableNew);
$sql = $this->platform->getAlterTableSQL($diff);
$this->assertEquals(
array('ALTER TABLE test ADD PRIMARY KEY (id)'),
$sql
);
}
}