Skip to content

Commit 54595a5

Browse files
committed
Update README & fix fluent index
1 parent 0f616aa commit 54595a5

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,17 @@ Schema::create('table', function (Blueprint $table) {
195195

196196
```
197197

198-
Sort keys by default works for `asc` sort queries. If you would like to create a sort key with `desc` order, you can use the `sortKeyDesc` method.
198+
Sort keys by default works only for `asc` sort queries. If you would like to create a sort key with `desc` order, you can set the key direction.
199199

200200
```php
201201
Schema::create('table', function (Blueprint $table) {
202202
$table->string('name');
203203

204-
$table->sortKeyDesc('name');
204+
$table->sortKey('name', 'desc');
205205
});
206206

207207
Schema::create('table', function (Blueprint $table) {
208-
$table->string('name')->sortKeyDesc();
208+
$table->string('name')->sortKey('desc');
209209
});
210210
```
211211

src/Schema/Blueprint/InlinesIndexes.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@ protected function addFluentSingleStoreIndexes()
117117
foreach ($this->columns as $column) {
118118
foreach ($this->singleStoreIndexes as $index) {
119119
if (isset($column->{$index})) {
120-
$this->{$index}($column->name, ($column->{$index} === true ? null : $column->{$index}));
120+
if ($column->{$index} === true) {
121+
$this->{$index}($column->name);
122+
} else {
123+
$this->{$index}($column->name, $column->{$index});
124+
}
125+
121126
$column->{$index} = false;
122127
}
123128
}

src/Schema/Blueprint/ModifiesIndexes.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,21 @@ trait ModifiesIndexes
1111
{
1212
/**
1313
* @param $columns
14-
* @param $name
1514
* @return \Illuminate\Support\Fluent
1615
*/
17-
public function shardKey($columns, $name = null)
16+
public function shardKey($columns)
1817
{
19-
return $this->indexCommand('shardKey', $columns, $name);
18+
return $this->indexCommand('shardKey', $columns, null);
2019
}
2120

2221
/**
2322
* @param $columns
24-
* @param $name
23+
* @param $direction
2524
* @return \Illuminate\Support\Fluent
2625
*/
27-
public function sortKey($columns, $name = null, $direction = 'asc')
26+
public function sortKey($columns, $direction = 'asc')
2827
{
29-
$command = $this->indexCommand('sortKey', $columns, $name);
28+
$command = $this->indexCommand('sortKey', $columns, null);
3029
$command->direction = $direction;
3130

3231
return $command;

tests/Hybrid/CreateTable/SortKeysTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ public function it_adds_a_sort_key_standalone()
2828
}
2929

3030
/** @test */
31-
public function it_adds_a_sort_key_desc_standalone()
31+
public function it_adds_a_sort_key_with_desc_direction_standalone()
3232
{
3333
$blueprint = $this->createTable(function (Blueprint $table) {
3434
$table->string('name');
35-
$table->sortKey(columns: 'name', direction: 'desc');
35+
$table->sortKey('name', 'desc');
3636
});
3737

3838
$this->assertCreateStatement(
@@ -54,6 +54,19 @@ public function it_adds_a_sort_key_fluent()
5454
);
5555
}
5656

57+
/** @test */
58+
public function it_adds_a_sort_key_with_desc_direction_fluent()
59+
{
60+
$blueprint = $this->createTable(function (Blueprint $table) {
61+
$table->string('name')->sortKey('desc');
62+
});
63+
64+
$this->assertCreateStatement(
65+
$blueprint,
66+
'create table `test` (`name` varchar(255) not null, sort key(`name` desc))'
67+
);
68+
}
69+
5770
/** @test */
5871
public function it_adds_a_dual_sort_key()
5972
{

0 commit comments

Comments
 (0)