Skip to content

Commit 1f2c88f

Browse files
committed
#1318 Implement dropping all tables with mongo driver
1 parent 8c17827 commit 1f2c88f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/Jenssegers/Mongodb/Schema/Builder.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,38 @@ public function drop($collection)
106106
return $blueprint->drop();
107107
}
108108

109+
/**
110+
* @inheritdoc
111+
*/
112+
public function dropAllTables()
113+
{
114+
foreach ($this->getAllCollections() as $collection) {
115+
$this->drop($collection);
116+
}
117+
}
118+
109119
/**
110120
* @inheritdoc
111121
*/
112122
protected function createBlueprint($collection, Closure $callback = null)
113123
{
114124
return new Blueprint($this->connection, $collection);
115125
}
126+
127+
/**
128+
* Get all of the collections names for the database.
129+
*
130+
* @return array
131+
*/
132+
protected function getAllCollections()
133+
{
134+
135+
$collections = [];
136+
foreach($this->connection->getMongoDB()->listCollections() as $collection) {
137+
$collections[] = $collection->getName();
138+
}
139+
140+
return $collections;
141+
}
142+
116143
}

0 commit comments

Comments
 (0)