Skip to content

Commit ad5bc11

Browse files
Added deleteAllCollections (#38)
* Dried up deleteAllAnalyzers code * Added deleteAllCollections * Added deleteAllCollections
1 parent 76c9d50 commit ad5bc11

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

docs/schema-collections.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,10 @@ Delete a collection
8181
```
8282
$arangoClient->schema()->deleteCollection('users');
8383
```
84+
### deleteAllCollections(): bool
85+
This method deletes all non-system collections available on the current database.
86+
87+
```
88+
$arangoClient->schema()->deleteAllCollections();
89+
```
8490

src/Schema/ManagesAnalyzers.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ public function deleteAllAnalyzers(): bool
7171
continue;
7272
}
7373

74-
$uri = '/_api/analyzer/' . $analyzer->name;
75-
76-
$this->arangoClient->request('delete', $uri);
74+
$this->deleteAnalyzer($analyzer->name);
7775
}
7876

7977
return true;

src/Schema/ManagesCollections.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,18 @@ public function deleteCollection(string $name): bool
214214

215215
return (bool) $this->arangoClient->request('delete', $uri);
216216
}
217+
218+
/**
219+
* @throws ArangoException
220+
*/
221+
public function deleteAllCollections(): bool
222+
{
223+
$collections = $this->getCollections(true);
224+
225+
foreach ($collections as $collection) {
226+
$this->deleteCollection($collection->name);
227+
}
228+
229+
return true;
230+
}
217231
}

tests/SchemaManagerCollectionsTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,28 @@
192192

193193
$this->schemaManager->deleteCollection($collection);
194194
});
195+
196+
test('deleteAllCollections', function () {
197+
$collection1 = 'collection1';
198+
$collection2 = 'collection2';
199+
200+
if (!$this->schemaManager->hasCollection($collection1)) {
201+
$result = $this->schemaManager->createCollection($collection1, []);
202+
expect($result->name)->toEqual($collection1);
203+
}
204+
205+
if (!$this->schemaManager->hasCollection($collection2)) {
206+
$result = $this->schemaManager->createCollection($collection2, []);
207+
expect($result->name)->toEqual($collection2);
208+
}
209+
210+
$createdCollections = $this->schemaManager->getCollections(true);
211+
212+
$result = $this->schemaManager->deleteAllCollections();
213+
214+
$finalCollections = $this->schemaManager->getCollections(true);
215+
216+
expect($result)->toBeTrue();
217+
expect(count($createdCollections))->toBe(2);
218+
expect(count($finalCollections))->toBe(0);
219+
});

0 commit comments

Comments
 (0)