Skip to content

Commit 0822654

Browse files
committed
Index: changed order of $type & $columns (BC break)
1 parent f72944a commit 0822654

6 files changed

Lines changed: 14 additions & 14 deletions

File tree

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ $table = $schema->addTable('book');
2929
$table->addColumn('id', 'INT', NULL, array('UNSIGNED'));
3030
$table->addColumn('name', 'VARCHAR', array(200));
3131
$table->addColumn('author_id', 'INT', NULL, array('UNSIGNED'));
32-
$table->addIndex(NULL, Index::TYPE_PRIMARY, 'id');
33-
$table->addIndex('name_author_id', Index::TYPE_UNIQUE, array('name', 'author_id'));
32+
$table->addIndex(NULL, 'id', Index::TYPE_PRIMARY);
33+
$table->addIndex('name_author_id', array('name', 'author_id'), Index::TYPE_UNIQUE);
3434

3535
$schema->getTables();
3636
```

src/Index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ class Index
2121

2222

2323
/**
24-
* @param string
2524
* @param string
2625
* @param string[]|string
26+
* @param string
2727
*/
28-
public function __construct($name, $type = self::TYPE_INDEX, $columns = array())
28+
public function __construct($name, $columns = array(), $type = self::TYPE_INDEX)
2929
{
3030
$this->name = $name;
3131
$this->setType($type);

src/Table.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ public function getColumns()
134134

135135
/**
136136
* @param string|Index|NULL
137-
* @param string
138137
* @param string[]|string
138+
* @param string
139139
* @return Index
140140
*/
141-
public function addIndex($name, $type = Index::TYPE_INDEX, $columns = array())
141+
public function addIndex($name, $columns = array(), $type = Index::TYPE_INDEX)
142142
{
143143
$index = NULL;
144144

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

149149
} else {
150-
$index = new Index($name, $type, $columns);
150+
$index = new Index($name, $columns, $type);
151151
$name = $index->getName();
152152
}
153153

tests/SqlSchema/Index.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require __DIR__ . '/../bootstrap.php';
77

88

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

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

1919

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

2525

2626
test(function () {
2727
Assert::exception(function () {
28-
$index = new CzProject\SqlSchema\Index('', 'BLA');
28+
$index = new CzProject\SqlSchema\Index('', array(), 'BLA');
2929

3030
}, 'CzProject\SqlSchema\OutOfRangeException', "Index type 'BLA' not found.");
3131
});

tests/SqlSchema/Table.validate.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ test(function () {
1919
Assert::exception(function () {
2020
$table = new Table('book');
2121
$table->addColumn('id', 'INT');
22-
$table->addIndex('id', Index::TYPE_PRIMARY);
23-
$table->addIndex('primary', Index::TYPE_PRIMARY);
22+
$table->addIndex('id', array(), Index::TYPE_PRIMARY);
23+
$table->addIndex('primary', array(), Index::TYPE_PRIMARY);
2424
$table->validate();
2525
}, 'CzProject\\SqlSchema\\DuplicateException', "Duplicated primary index in table 'book'.");
2626
});

tests/SqlSchema/readme.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ test(function () {
1313
$table->addColumn('id', 'INT', NULL, array('UNSIGNED'));
1414
$table->addColumn('name', 'VARCHAR', array(200));
1515
$table->addColumn('author_id', 'INT', NULL, array('UNSIGNED'));
16-
$table->addIndex(NULL, Index::TYPE_PRIMARY, 'id');
17-
$table->addIndex('name_author_id', Index::TYPE_UNIQUE, array('name', 'author_id'));
16+
$table->addIndex(NULL, 'id', Index::TYPE_PRIMARY);
17+
$table->addIndex('name_author_id', array('name', 'author_id'), Index::TYPE_UNIQUE);
1818

1919
$schema->getTables();
2020

0 commit comments

Comments
 (0)