Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
laravel-mongodb
Commits
9e4786cc
Unverified
Commit
9e4786cc
authored
Apr 03, 2018
by
Jens Segers
Committed by
GitHub
Apr 03, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1479 from mnich0ls/drop-index
Fix drop index
parents
25abcc90
7adb4378
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
11 deletions
+36
-11
Blueprint.php
src/Jenssegers/Mongodb/Schema/Blueprint.php
+7
-10
SchemaTest.php
tests/SchemaTest.php
+29
-1
No files found.
src/Jenssegers/Mongodb/Schema/Blueprint.php
View file @
9e4786cc
...
...
@@ -76,25 +76,22 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
/**
* @inheritdoc
*/
public
function
dropIndex
(
$
c
olumns
=
null
)
public
function
dropIndex
(
$
indexOrC
olumns
=
null
)
{
$columns
=
$this
->
fluent
(
$columns
);
if
(
is_array
(
$indexOrColumns
))
{
$indexOrColumns
=
$this
->
fluent
(
$indexOrColumns
);
// Columns are passed as a default array.
if
(
is_array
(
$columns
)
&&
is_int
(
key
(
$columns
)))
{
// Transform the columns to the required array format.
// Transform the columns to the index name.
$transform
=
[];
foreach
(
$
c
olumns
as
$column
)
{
foreach
(
$
indexOrC
olumns
as
$column
)
{
$transform
[
$column
]
=
$column
.
'_1'
;
}
$
columns
=
$transform
;
$
indexOrColumns
=
join
(
'_'
,
$transform
)
;
}
foreach
(
$columns
as
$column
)
{
$this
->
collection
->
dropIndex
(
$column
);
}
$this
->
collection
->
dropIndex
(
$indexOrColumns
);
return
$this
;
}
...
...
tests/SchemaTest.php
View file @
9e4786cc
...
...
@@ -93,7 +93,7 @@ class SchemaTest extends TestCase
{
Schema
::
collection
(
'newcollection'
,
function
(
$collection
)
{
$collection
->
unique
(
'uniquekey'
);
$collection
->
dropIndex
(
'uniquekey'
);
$collection
->
dropIndex
(
'uniquekey
_1
'
);
});
$index
=
$this
->
getIndex
(
'newcollection'
,
'uniquekey'
);
...
...
@@ -106,6 +106,34 @@ class SchemaTest extends TestCase
$index
=
$this
->
getIndex
(
'newcollection'
,
'uniquekey'
);
$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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment