77use  Closure ;
88use  MongoDB \Collection ;
99use  MongoDB \Driver \Exception \ServerException ;
10+ use  MongoDB \Laravel \Connection ;
1011use  MongoDB \Model \CollectionInfo ;
1112use  MongoDB \Model \IndexInfo ;
1213
1617use  function  array_keys ;
1718use  function  array_map ;
1819use  function  array_merge ;
20+ use  function  array_values ;
1921use  function  assert ;
2022use  function  count ;
2123use  function  current ;
2224use  function  implode ;
2325use  function  in_array ;
26+ use  function  is_array ;
27+ use  function  is_string ;
2428use  function  iterator_to_array ;
2529use  function  sort ;
2630use  function  sprintf ;
2731use  function  str_ends_with ;
2832use  function  substr ;
2933use  function  usort ;
3034
35+ /** @property Connection $connection */ 
3136class  Builder extends  \Illuminate \Database \Schema \Builder
3237{
3338    /** 
@@ -137,9 +142,10 @@ public function dropAllTables()
137142        }
138143    }
139144
140-     public  function  getTables ()
145+     /** @param string|null $schema Database name */ 
146+     public  function  getTables ($ schemanull )
141147    {
142-         $ db$ this connection ->getDatabase ();
148+         $ db$ this connection ->getDatabase ($ schema 
143149        $ collections
144150
145151        foreach  ($ dblistCollectionNames () as  $ collectionName
@@ -150,7 +156,8 @@ public function getTables()
150156
151157            $ collections
152158                'name '  => $ collectionName
153-                 'schema '  => null ,
159+                 'schema '  => $ dbgetDatabaseName (),
160+                 'schema_qualified_name '  => $ dbgetDatabaseName () . '. '  . $ collectionName
154161                'size '  => $ stats0 ]?->storageStats?->totalSize ?? null ,
155162                'comment '  => null ,
156163                'collation '  => null ,
@@ -165,9 +172,29 @@ public function getTables()
165172        return  $ collections
166173    }
167174
168-     public  function  getTableListing ()
175+     /** 
176+      * @param string|null $schema 
177+      * @param bool        $schemaQualified If a schema is provided, prefix the collection names with the schema name 
178+      * 
179+      * @return array 
180+      */ 
181+     public  function  getTableListing ($ schemanull , $ schemaQualifiedfalse )
169182    {
170-         $ collectionsiterator_to_array ($ this connection ->getDatabase ()->listCollectionNames ());
183+         $ collections
184+ 
185+         if  ($ schemanull  || is_string ($ schema
186+             $ collections$ schema0 ] = iterator_to_array ($ this connection ->getDatabase ($ schemalistCollectionNames ());
187+         } elseif  (is_array ($ schema
188+             foreach  ($ schemaas  $ db
189+                 $ collections$ dbiterator_to_array ($ this connection ->getDatabase ($ dblistCollectionNames ());
190+             }
191+         }
192+ 
193+         if  ($ schema$ schemaQualified
194+             $ collectionsarray_map (fn  ($ db$ collectionsarray_map (static  fn  ($ collection$ db'. '  . $ collection$ collectionsarray_keys ($ collections$ collections
195+         }
196+ 
197+         $ collectionsarray_merge (...array_values ($ collections
171198
172199        sort ($ collections
173200
0 commit comments