Skip to content

Commit 0e9007e

Browse files
committed
Making sure we are not making non-uniques and non-primary keys index. Also changing basic fixture schema to make tests pass.
1 parent fb476f1 commit 0e9007e

File tree

6 files changed

+35
-8
lines changed

6 files changed

+35
-8
lines changed

cake/libs/model/datasources/dbo/dbo_mssql.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,8 +703,8 @@ function buildIndex($indexes, $table = null) {
703703

704704
foreach ($indexes as $name => $value) {
705705
if ($name == 'PRIMARY') {
706-
$out = 'PRIMARY KEY (' . $this->name($value['column']) . ')';
707-
} else {
706+
$join[] = 'PRIMARY KEY (' . $this->name($value['column']) . ')';
707+
} else if (isset($value['unique']) && $value['unique']) {
708708
$out = "ALTER TABLE {$table} ADD CONSTRAINT {$name} UNIQUE";
709709

710710
if (is_array($value['column'])) {
@@ -713,8 +713,8 @@ function buildIndex($indexes, $table = null) {
713713
$value['column'] = $this->name($value['column']);
714714
}
715715
$out .= "({$value['column']});";
716+
$join[] = $out;
716717
}
717-
$join[] = $out;
718718
}
719719
return $join;
720720
}

cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,33 @@ function testBuildColumn() {
519519
$expected = '[name] varchar(255) DEFAULT \'\'';
520520
$this->assertEqual($result, $expected);
521521
}
522+
/**
523+
* testBuildIndex method
524+
*
525+
* @return void
526+
* @access public
527+
*/
528+
function testBuildIndex() {
529+
$indexes = array(
530+
'PRIMARY' => array('column' => 'id', 'unique' => 1),
531+
'client_id' => array('column' => 'client_id', 'unique' => 1)
532+
);
533+
$result = $this->db->buildIndex($indexes, 'items');
534+
$expected = array(
535+
'PRIMARY KEY ([id])',
536+
'ALTER TABLE items ADD CONSTRAINT client_id UNIQUE([client_id]);'
537+
);
538+
$this->assertEqual($result, $expected);
539+
540+
$indexes = array('client_id' => array('column' => 'client_id'));
541+
$result = $this->db->buildIndex($indexes, 'items');
542+
$this->assertEqual($result, array());
543+
544+
$indexes = array('client_id' => array('column' => array('client_id', 'period_id'), 'unique' => 1));
545+
$result = $this->db->buildIndex($indexes, 'items');
546+
$expected = array('ALTER TABLE items ADD CONSTRAINT client_id UNIQUE([client_id], [period_id]);');
547+
$this->assertEqual($result, $expected);
548+
}
522549
/**
523550
* testUpdateAllSyntax method
524551
*

cake/tests/fixtures/aco_fixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class AcoFixture extends CakeTestFixture {
4747
var $fields = array(
4848
'id' => array('type' => 'integer', 'key' => 'primary'),
4949
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
50-
'model' => array('type' => 'string', 'default' => ''),
50+
'model' => array('type' => 'string', 'null' => true),
5151
'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true),
5252
'alias' => array('type' => 'string', 'default' => ''),
5353
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),

cake/tests/fixtures/aco_two_fixture.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class AcoTwoFixture extends CakeTestFixture {
4646
*/
4747
var $fields = array(
4848
'id' => array('type' => 'integer', 'key' => 'primary'),
49-
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true, 'default' => 0),
50-
'model' => array('type' => 'string', 'default' => ''),
49+
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
50+
'model' => array('type' => 'string', 'null' => true),
5151
'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true),
5252
'alias' => array('type' => 'string', 'default' => ''),
5353
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),

cake/tests/fixtures/aro_fixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class AroFixture extends CakeTestFixture {
4747
var $fields = array(
4848
'id' => array('type' => 'integer', 'key' => 'primary'),
4949
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
50-
'model' => array('type' => 'string', 'default' => ''),
50+
'model' => array('type' => 'string', 'null' => true),
5151
'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true),
5252
'alias' => array('type' => 'string', 'default' => ''),
5353
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),

cake/tests/fixtures/aro_two_fixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class AroTwoFixture extends CakeTestFixture {
4747
var $fields = array(
4848
'id' => array('type' => 'integer', 'key' => 'primary'),
4949
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
50-
'model' => array('type' => 'string', 'default' => ''),
50+
'model' => array('type' => 'string', 'null' => true),
5151
'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true),
5252
'alias' => array('type' => 'string', 'default' => ''),
5353
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),

0 commit comments

Comments
 (0)