@@ -143,7 +143,7 @@ public function dropAllTables()
143143 }
144144 }
145145
146- /** @param string|null $schema Database name */
146+ /** @param string|null $schema Database name */
147147 public function getTables ($ schema = null )
148148 {
149149 $ db = $ this ->connection ->getDatabase ($ schema );
@@ -161,12 +161,8 @@ public function getTables($schema = null)
161161 $ isView = ($ collectionInfo ['type ' ] ?? '' ) === 'view ' ;
162162 $ stats = null ;
163163
164- if (! $ isView ) {
165- // Only run aggregation if it's a normal collection
166- $ stats = $ db ->selectCollection ($ collectionName )->aggregate ([
167- ['$collStats ' => ['storageStats ' => ['scale ' => 1 ]]],
168- ['$project ' => ['storageStats.totalSize ' => 1 ]],
169- ])->toArray ();
164+ if ($ isView ) {
165+ continue ;
170166 }
171167
172168 $ collections [] = [
@@ -176,7 +172,45 @@ public function getTables($schema = null)
176172 'size ' => $ stats [0 ]?->storageStats?->totalSize ?? null ,
177173 'comment ' => null ,
178174 'collation ' => null ,
179- 'engine ' => $ isView ? 'view ' : 'collection ' ,
175+ 'engine ' => null ,
176+ ];
177+ }
178+
179+ usort ($ collections , fn ($ a , $ b ) => $ a ['name ' ] <=> $ b ['name ' ]);
180+
181+ return $ collections ;
182+ }
183+
184+ /** @param string|null $schema Database name */
185+ public function getViews ($ schema = null )
186+ {
187+ $ db = $ this ->connection ->getDatabase ($ schema );
188+ $ collections = [];
189+
190+ foreach ($ db ->listCollections () as $ collectionInfo ) {
191+ $ collectionName = $ collectionInfo ->getName ();
192+
193+ // Skip system collections
194+ if (str_starts_with ($ collectionName , 'system. ' )) {
195+ continue ;
196+ }
197+
198+ // Skip views it doesnt suport aggregate
199+ $ isView = ($ collectionInfo ['type ' ] ?? '' ) === 'view ' ;
200+ $ stats = null ;
201+
202+ if (! $ isView ) {
203+ continue ;
204+ }
205+
206+ $ collections [] = [
207+ 'name ' => $ collectionName ,
208+ 'schema ' => $ db ->getDatabaseName (),
209+ 'schema_qualified_name ' => $ db ->getDatabaseName () . '. ' . $ collectionName ,
210+ 'size ' => null ,
211+ 'comment ' => null ,
212+ 'collation ' => null ,
213+ 'engine ' => null ,
180214 ];
181215 }
182216
0 commit comments