Unverified Commit 9e4786cc authored by Jens Segers's avatar Jens Segers Committed by GitHub

Merge pull request #1479 from mnich0ls/drop-index

Fix drop index
parents 25abcc90 7adb4378
...@@ -76,25 +76,22 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint ...@@ -76,25 +76,22 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function dropIndex($columns = null) public function dropIndex($indexOrColumns = null)
{ {
$columns = $this->fluent($columns); if (is_array($indexOrColumns)) {
$indexOrColumns = $this->fluent($indexOrColumns);
// Columns are passed as a default array. // Transform the columns to the index name.
if (is_array($columns) && is_int(key($columns))) {
// Transform the columns to the required array format.
$transform = []; $transform = [];
foreach ($columns as $column) { foreach ($indexOrColumns as $column) {
$transform[$column] = $column . '_1'; $transform[$column] = $column . '_1';
} }
$columns = $transform; $indexOrColumns = join('_', $transform);
} }
foreach ($columns as $column) { $this->collection->dropIndex($indexOrColumns);
$this->collection->dropIndex($column);
}
return $this; return $this;
} }
......
...@@ -93,7 +93,7 @@ class SchemaTest extends TestCase ...@@ -93,7 +93,7 @@ class SchemaTest extends TestCase
{ {
Schema::collection('newcollection', function ($collection) { Schema::collection('newcollection', function ($collection) {
$collection->unique('uniquekey'); $collection->unique('uniquekey');
$collection->dropIndex('uniquekey'); $collection->dropIndex('uniquekey_1');
}); });
$index = $this->getIndex('newcollection', 'uniquekey'); $index = $this->getIndex('newcollection', 'uniquekey');
...@@ -106,6 +106,34 @@ class SchemaTest extends TestCase ...@@ -106,6 +106,34 @@ class SchemaTest extends TestCase
$index = $this->getIndex('newcollection', 'uniquekey'); $index = $this->getIndex('newcollection', 'uniquekey');
$this->assertEquals(null, $index); $this->assertEquals(null, $index);
Schema::collection('newcollection', function ($collection) {
$collection->index(['field_a', 'field_b']);
});
$index = $this->getIndex('newcollection', 'field_a_1_field_b_1');
$this->assertNotNull($index);
Schema::collection('newcollection', function ($collection) {
$collection->dropIndex(['field_a', 'field_b']);
});
$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');
});
$index = $this->getIndex('newcollection', 'custom_index_name');
$this->assertNotNull($index);
Schema::collection('newcollection', function ($collection) {
$collection->dropIndex('custom_index_name');
});
$index = $this->getIndex('newcollection', 'custom_index_name');
$this->assertFalse($index);
} }
public function testBackground() public function testBackground()
......
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