Commit ca0f710a authored by Mauri de Souza Nunes's avatar Mauri de Souza Nunes

Fix dropIndex for compound indexes with sorting order

parent ef147ea5
...@@ -129,8 +129,18 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -129,8 +129,18 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
// Transform the columns to the index name. // Transform the columns to the index name.
$transform = []; $transform = [];
foreach ($indexOrColumns as $column) { foreach ($indexOrColumns as $key => $value) {
$transform[$column] = $column . '_1'; if (is_int($key)) {
// There is no sorting order, use the default.
$column = $value;
$sorting = '1';
} else {
// This is a column with sorting order e.g 'my_column' => -1.
$column = $key;
$sorting = $value;
}
$transform[$column] = $column . "_" . $sorting;
} }
$indexOrColumns = implode('_', $transform); $indexOrColumns = implode('_', $transform);
......
...@@ -132,6 +132,20 @@ class SchemaTest extends TestCase ...@@ -132,6 +132,20 @@ class SchemaTest extends TestCase
$index = $this->getIndex('newcollection', 'field_a_1_field_b_1'); $index = $this->getIndex('newcollection', 'field_a_1_field_b_1');
$this->assertFalse($index); $this->assertFalse($index);
Schema::collection('newcollection', function ($collection) {
$collection->index(['field_a' => -1, 'field_b' => 1]);
});
$index = $this->getIndex('newcollection', 'field_a_-1_field_b_1');
$this->assertNotNull($index);
Schema::collection('newcollection', function ($collection) {
$collection->dropIndex(['field_a' => -1, 'field_b' => 1]);
});
$index = $this->getIndex('newcollection', 'field_a_-1_field_b_1');
$this->assertFalse($index);
Schema::collection('newcollection', function ($collection) { Schema::collection('newcollection', function ($collection) {
$collection->index(['field_a', 'field_b'], 'custom_index_name'); $collection->index(['field_a', 'field_b'], 'custom_index_name');
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment