Skip to content

Commit f527d38

Browse files
committed
implement removeIndex method
1 parent e36773a commit f527d38

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/Repository.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ public function save($instance)
257257
}
258258

259259

260+
$this->flushCache();
261+
}
262+
263+
public function flushCache()
264+
{
260265
$this->cache = [];
261266
}
262267
}

src/Space.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ public function addProperty($name, $type)
3535
$this->parseFormat();
3636
}
3737

38+
public function removeIndex($name)
39+
{
40+
$this->mapper->getClient()->evaluate("box.space[$this->id].index.$name:drop()");
41+
$this->indexes = [];
42+
$this->mapper->getRepository('_index')->flushCache();
43+
}
44+
3845
public function createIndex($config)
3946
{
4047

tests/SchemaTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,27 @@
66

77
class SchemaTest extends TestCase
88
{
9+
public function testRemoveIndex()
10+
{
11+
$mapper = $this->createMapper();
12+
$this->clean($mapper);
13+
14+
$space = $mapper->getSchema()->createSpace('tester');
15+
$space->addProperty('id', 'unsigned');
16+
$space->addProperty('iid', 'unsigned');
17+
18+
$space->createIndex(['id']);
19+
$space->createIndex(['iid']);
20+
21+
$this->assertCount(2, $space->getIndexes());
22+
23+
$space->removeIndex('iid');
24+
$this->assertCount(1, $space->getIndexes());
25+
26+
$this->expectException(Exception::class);
27+
$space->removeIndex('iid');
28+
}
29+
930
public function testNoSpaceException()
1031
{
1132
$mapper = $this->createMapper();

0 commit comments

Comments
 (0)