Commit 4d81b402 authored by Stas's avatar Stas Committed by GitHub

Merge pull request #1885 from mauri870/drop-compound-index

Fix dropIndex for compound indexes with sorting order
parents c6313cb2 9b062ac0
......@@ -129,8 +129,18 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
// Transform the columns to the index name.
$transform = [];
foreach ($indexOrColumns as $column) {
$transform[$column] = $column . '_1';
foreach ($indexOrColumns as $key => $value) {
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);
......
......@@ -132,6 +132,20 @@ class SchemaTest extends TestCase
$index = $this->getIndex('newcollection', 'field_a_1_field_b_1');
$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) {
$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