Skip to content

Commit

Permalink
Making sure we are not making non-uniques and non-primary keys index.…
Browse files Browse the repository at this point in the history
… Also changing basic fixture schema to make tests pass.
  • Loading branch information
renan committed Sep 3, 2009
1 parent fb476f1 commit 0e9007e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
6 changes: 3 additions & 3 deletions cake/libs/model/datasources/dbo/dbo_mssql.php
Expand Up @@ -703,8 +703,8 @@ function buildIndex($indexes, $table = null) {


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


if (is_array($value['column'])) { if (is_array($value['column'])) {
Expand All @@ -713,8 +713,8 @@ function buildIndex($indexes, $table = null) {
$value['column'] = $this->name($value['column']); $value['column'] = $this->name($value['column']);
} }
$out .= "({$value['column']});"; $out .= "({$value['column']});";
$join[] = $out;
} }
$join[] = $out;
} }
return $join; return $join;
} }
Expand Down
27 changes: 27 additions & 0 deletions cake/tests/cases/libs/model/datasources/dbo/dbo_mssql.test.php
Expand Up @@ -519,6 +519,33 @@ function testBuildColumn() {
$expected = '[name] varchar(255) DEFAULT \'\''; $expected = '[name] varchar(255) DEFAULT \'\'';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
} }
/**
* testBuildIndex method
*
* @return void
* @access public
*/
function testBuildIndex() {
$indexes = array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'client_id' => array('column' => 'client_id', 'unique' => 1)
);
$result = $this->db->buildIndex($indexes, 'items');
$expected = array(
'PRIMARY KEY ([id])',
'ALTER TABLE items ADD CONSTRAINT client_id UNIQUE([client_id]);'
);
$this->assertEqual($result, $expected);

$indexes = array('client_id' => array('column' => 'client_id'));
$result = $this->db->buildIndex($indexes, 'items');
$this->assertEqual($result, array());

$indexes = array('client_id' => array('column' => array('client_id', 'period_id'), 'unique' => 1));
$result = $this->db->buildIndex($indexes, 'items');
$expected = array('ALTER TABLE items ADD CONSTRAINT client_id UNIQUE([client_id], [period_id]);');
$this->assertEqual($result, $expected);
}
/** /**
* testUpdateAllSyntax method * testUpdateAllSyntax method
* *
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/fixtures/aco_fixture.php
Expand Up @@ -47,7 +47,7 @@ class AcoFixture extends CakeTestFixture {
var $fields = array( var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'), 'id' => array('type' => 'integer', 'key' => 'primary'),
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true), 'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
'model' => array('type' => 'string', 'default' => ''), 'model' => array('type' => 'string', 'null' => true),
'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true), 'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true),
'alias' => array('type' => 'string', 'default' => ''), 'alias' => array('type' => 'string', 'default' => ''),
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true), 'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),
Expand Down
4 changes: 2 additions & 2 deletions cake/tests/fixtures/aco_two_fixture.php
Expand Up @@ -46,8 +46,8 @@ class AcoTwoFixture extends CakeTestFixture {
*/ */
var $fields = array( var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'), 'id' => array('type' => 'integer', 'key' => 'primary'),
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true, 'default' => 0), 'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
'model' => array('type' => 'string', 'default' => ''), 'model' => array('type' => 'string', 'null' => true),
'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true), 'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true),
'alias' => array('type' => 'string', 'default' => ''), 'alias' => array('type' => 'string', 'default' => ''),
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true), 'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/fixtures/aro_fixture.php
Expand Up @@ -47,7 +47,7 @@ class AroFixture extends CakeTestFixture {
var $fields = array( var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'), 'id' => array('type' => 'integer', 'key' => 'primary'),
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true), 'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
'model' => array('type' => 'string', 'default' => ''), 'model' => array('type' => 'string', 'null' => true),
'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true), 'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true),
'alias' => array('type' => 'string', 'default' => ''), 'alias' => array('type' => 'string', 'default' => ''),
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true), 'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/fixtures/aro_two_fixture.php
Expand Up @@ -47,7 +47,7 @@ class AroTwoFixture extends CakeTestFixture {
var $fields = array( var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'), 'id' => array('type' => 'integer', 'key' => 'primary'),
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true), 'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
'model' => array('type' => 'string', 'default' => ''), 'model' => array('type' => 'string', 'null' => true),
'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true), 'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true),
'alias' => array('type' => 'string', 'default' => ''), 'alias' => array('type' => 'string', 'default' => ''),
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true), 'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),
Expand Down

0 comments on commit 0e9007e

Please sign in to comment.