Skip to content

Commit

Permalink
Index: changed order of $type & $columns (BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
janpecha committed Apr 24, 2018
1 parent f72944a commit 0822654
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ $table = $schema->addTable('book');
$table->addColumn('id', 'INT', NULL, array('UNSIGNED'));
$table->addColumn('name', 'VARCHAR', array(200));
$table->addColumn('author_id', 'INT', NULL, array('UNSIGNED'));
$table->addIndex(NULL, Index::TYPE_PRIMARY, 'id');
$table->addIndex('name_author_id', Index::TYPE_UNIQUE, array('name', 'author_id'));
$table->addIndex(NULL, 'id', Index::TYPE_PRIMARY);
$table->addIndex('name_author_id', array('name', 'author_id'), Index::TYPE_UNIQUE);

$schema->getTables();
```
Expand Down
4 changes: 2 additions & 2 deletions src/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class Index


/**
* @param string
* @param string
* @param string[]|string
* @param string
*/
public function __construct($name, $type = self::TYPE_INDEX, $columns = array())
public function __construct($name, $columns = array(), $type = self::TYPE_INDEX)
{
$this->name = $name;
$this->setType($type);
Expand Down
6 changes: 3 additions & 3 deletions src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ public function getColumns()

/**
* @param string|Index|NULL
* @param string
* @param string[]|string
* @param string
* @return Index
*/
public function addIndex($name, $type = Index::TYPE_INDEX, $columns = array())
public function addIndex($name, $columns = array(), $type = Index::TYPE_INDEX)
{
$index = NULL;

Expand All @@ -147,7 +147,7 @@ public function addIndex($name, $type = Index::TYPE_INDEX, $columns = array())
$name = $index->getName();

} else {
$index = new Index($name, $type, $columns);
$index = new Index($name, $columns, $type);
$name = $index->getName();
}

Expand Down
6 changes: 3 additions & 3 deletions tests/SqlSchema/Index.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require __DIR__ . '/../bootstrap.php';


test(function () {
$index = new CzProject\SqlSchema\Index('index_name', Index::TYPE_PRIMARY, 'id');
$index = new CzProject\SqlSchema\Index('index_name', 'id', Index::TYPE_PRIMARY);

Assert::same('index_name', $index->getName());
Assert::same('PRIMARY', $index->getType());
Expand All @@ -18,14 +18,14 @@ test(function () {


test(function () {
$index = new CzProject\SqlSchema\Index('id_name', Index::TYPE_INDEX, array('id', 'name'));
$index = new CzProject\SqlSchema\Index('id_name', array('id', 'name'));
Assert::same('id_name', $index->getName());
});


test(function () {
Assert::exception(function () {
$index = new CzProject\SqlSchema\Index('', 'BLA');
$index = new CzProject\SqlSchema\Index('', array(), 'BLA');

}, 'CzProject\SqlSchema\OutOfRangeException', "Index type 'BLA' not found.");
});
4 changes: 2 additions & 2 deletions tests/SqlSchema/Table.validate.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ test(function () {
Assert::exception(function () {
$table = new Table('book');
$table->addColumn('id', 'INT');
$table->addIndex('id', Index::TYPE_PRIMARY);
$table->addIndex('primary', Index::TYPE_PRIMARY);
$table->addIndex('id', array(), Index::TYPE_PRIMARY);
$table->addIndex('primary', array(), Index::TYPE_PRIMARY);
$table->validate();
}, 'CzProject\\SqlSchema\\DuplicateException', "Duplicated primary index in table 'book'.");
});
Expand Down
4 changes: 2 additions & 2 deletions tests/SqlSchema/readme.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ test(function () {
$table->addColumn('id', 'INT', NULL, array('UNSIGNED'));
$table->addColumn('name', 'VARCHAR', array(200));
$table->addColumn('author_id', 'INT', NULL, array('UNSIGNED'));
$table->addIndex(NULL, Index::TYPE_PRIMARY, 'id');
$table->addIndex('name_author_id', Index::TYPE_UNIQUE, array('name', 'author_id'));
$table->addIndex(NULL, 'id', Index::TYPE_PRIMARY);
$table->addIndex('name_author_id', array('name', 'author_id'), Index::TYPE_UNIQUE);

$schema->getTables();

Expand Down

0 comments on commit 0822654

Please sign in to comment.