Skip to content

Commit d5a6963

Browse files
committed
add key direction to all columns
1 parent 6f0e84c commit d5a6963

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/Schema/Grammar.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
class Grammar extends MySqlGrammar
1919
{
20-
use CompilesKeys, ModifiesColumns;
20+
use CompilesKeys;
21+
use ModifiesColumns;
2122

2223
public function __construct()
2324
{
@@ -64,7 +65,8 @@ protected function compileCreateTable($blueprint, $command, $connection)
6465
// We want to do as little as possible ourselves, so we rely on the parent
6566
// to compile everything and then potentially sneak some modifiers in.
6667
return $this->insertCreateTableModifiers(
67-
$blueprint, parent::compileCreateTable($blueprint, $command, $connection)
68+
$blueprint,
69+
parent::compileCreateTable($blueprint, $command, $connection)
6870
);
6971
}
7072

@@ -174,4 +176,19 @@ protected function compileKey(Blueprint $blueprint, Fluent $command, $type)
174176
// creating the indexes as a part of the create statement.
175177
return str_replace(sprintf('alter table %s add ', $this->wrapTable($blueprint)), '', $compiled);
176178
}
179+
180+
/**
181+
* Convert an array of column names into a delimited string (with direction parameter).
182+
*
183+
* @param array $columns
184+
* @return string
185+
*/
186+
protected function columnizeWithDirection(array $columns, string $direction)
187+
{
188+
$wrapped = array_map([$this, 'wrap'], $columns);
189+
190+
return implode(", ", array_map(function ($column) use ($direction) {
191+
return $column . ' ' . $direction;
192+
}, $wrapped));
193+
}
177194
}

src/Schema/Grammar/CompilesKeys.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +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)} {$command->direction})";
20+
return "sort key({$this->columnizeWithDirection($command->columns, $command->direction)})";
2121
}
2222

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

0 commit comments

Comments
 (0)