Skip to content

Commit 0f616aa

Browse files
committed
Move sort key desc to argument
1 parent cae2288 commit 0f616aa

File tree

5 files changed

+23
-92
lines changed

5 files changed

+23
-92
lines changed

src/Schema/Blueprint/InlinesIndexes.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ trait InlinesIndexes
1818
protected $singleStoreIndexes = [
1919
'shardKey',
2020
'sortKey',
21-
'sortKeyDesc'
2221
];
2322

2423
/**

src/Schema/Blueprint/ModifiesIndexes.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,12 @@ public function shardKey($columns, $name = null)
2424
* @param $name
2525
* @return \Illuminate\Support\Fluent
2626
*/
27-
public function sortKey($columns, $name = null)
27+
public function sortKey($columns, $name = null, $direction = 'asc')
2828
{
29-
return $this->indexCommand('sortKey', $columns, $name);
30-
}
29+
$command = $this->indexCommand('sortKey', $columns, $name);
30+
$command->direction = $direction;
3131

32-
/**
33-
* @param $columns
34-
* @param $name
35-
* @return \Illuminate\Support\Fluent
36-
*/
37-
public function sortKeyDesc($columns, $name = null)
38-
{
39-
return $this->indexCommand('sortKeyDesc', $columns, $name);
32+
return $command;
4033
}
4134

4235
/**

src/Schema/Grammar/CompilesKeys.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ public function compileShardKey(Blueprint $blueprint, Fluent $command)
1717

1818
public function compileSortKey(Blueprint $blueprint, Fluent $command)
1919
{
20-
return "sort key({$this->columnize($command->columns)})";
21-
}
22-
23-
public function compileSortKeyDesc(Blueprint $blueprint, Fluent $command)
24-
{
25-
return "sort key({$this->columnize($command->columns)} desc)";
20+
return "sort key({$this->columnize($command->columns)} {$command->direction})";
2621
}
2722

2823
public function compileSpatialIndex(Blueprint $blueprint, Fluent $command)

tests/Hybrid/CreateTable/SortKeysDescTest.php

Lines changed: 0 additions & 70 deletions
This file was deleted.

tests/Hybrid/CreateTable/SortKeysTest.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,21 @@ public function it_adds_a_sort_key_standalone()
2323

2424
$this->assertCreateStatement(
2525
$blueprint,
26-
'create table `test` (`name` varchar(255) not null, sort key(`name`))'
26+
'create table `test` (`name` varchar(255) not null, sort key(`name` asc))'
27+
);
28+
}
29+
30+
/** @test */
31+
public function it_adds_a_sort_key_desc_standalone()
32+
{
33+
$blueprint = $this->createTable(function (Blueprint $table) {
34+
$table->string('name');
35+
$table->sortKey(columns: 'name', direction: 'desc');
36+
});
37+
38+
$this->assertCreateStatement(
39+
$blueprint,
40+
'create table `test` (`name` varchar(255) not null, sort key(`name` desc))'
2741
);
2842
}
2943

@@ -36,7 +50,7 @@ public function it_adds_a_sort_key_fluent()
3650

3751
$this->assertCreateStatement(
3852
$blueprint,
39-
'create table `test` (`name` varchar(255) not null, sort key(`name`))'
53+
'create table `test` (`name` varchar(255) not null, sort key(`name` asc))'
4054
);
4155
}
4256

@@ -51,7 +65,7 @@ public function it_adds_a_dual_sort_key()
5165

5266
$this->assertCreateStatement(
5367
$blueprint,
54-
'create table `test` (`f_name` varchar(255) not null, `l_name` varchar(255) not null, sort key(`f_name`, `l_name`))'
68+
'create table `test` (`f_name` varchar(255) not null, `l_name` varchar(255) not null, sort key(`f_name`, `l_name` asc))'
5569
);
5670
}
5771

@@ -64,7 +78,7 @@ public function shard_and_sort_keys()
6478

6579
$this->assertCreateStatement(
6680
$blueprint,
67-
'create table `test` (`name` varchar(255) not null, shard key(`name`), sort key(`name`))'
81+
'create table `test` (`name` varchar(255) not null, shard key(`name`), sort key(`name` asc))'
6882
);
6983
}
7084
}

0 commit comments

Comments
 (0)