@@ -114,19 +114,16 @@ public static function getName(): string
114114 }
115115
116116 /**
117- * Create a reader instance for a specific database
117+ * Create a reader instance for general operations (not database-specific)
118118 *
119- * @param Database|null $database
120119 * @return Reader
121120 * @throws \Exception
122121 */
123- private function createReaderForDatabase ( Database | null $ database ): Reader
122+ private function createReader ( ): Reader
124123 {
125124 return match ($ this ->source ) {
126125 static ::SOURCE_API => new APIReader (new Databases ($ this ->client )),
127- static ::SOURCE_DATABASE => new DatabaseReader (
128- call_user_func ($ this ->getDatabaseDB , new UtopiaDocument (['database ' => $ database ]))
129- ),
126+ static ::SOURCE_DATABASE => new DatabaseReader ($ this ->dbForProject , $ this ->getDatabaseDB ),
130127 default => throw new \Exception ('Unknown source ' ),
131128 };
132129 }
@@ -296,14 +293,7 @@ private function reportAuth(array $resources, array &$report): void
296293 */
297294 private function reportDatabases (array $ resources , array &$ report ): void
298295 {
299- // For reporting, we use a temporary reader with dbForProject for SOURCE_DATABASE
300- // or the API reader for SOURCE_API
301- $ reader = match ($ this ->source ) {
302- static ::SOURCE_API => new APIReader (new Databases ($ this ->client )),
303- static ::SOURCE_DATABASE => new DatabaseReader ($ this ->dbForProject , $ this ->getDatabaseDB ),
304- default => throw new \Exception ('Unknown source ' ),
305- };
306-
296+ $ reader = $ this ->createReader ();
307297 $ reader ->report ($ resources , $ report );
308298 }
309299
@@ -660,11 +650,11 @@ protected function exportGroupDatabases(int $batchSize, array $resources): void
660650 return ;
661651 }
662652
663- if (count ($ this ->cache ->get (Database::getName ()))> 0 ) {
653+ if (count ($ this ->cache ->get (Database::getName ())) > 0 ) {
664654 $ this ->exportTablesDB ($ batchSize , $ resources );
665655 }
666656
667- if (count ($ this ->cache ->get (DocumentsDB::getName ()))> 0 ) {
657+ if (count ($ this ->cache ->get (DocumentsDB::getName ())) > 0 ) {
668658 $ this ->exportDocumentsDB ($ batchSize , $ resources );
669659 }
670660 }
@@ -679,11 +669,7 @@ private function exportDatabases(int $batchSize, array $resources = []): void
679669 $ lastDatabase = null ;
680670
681671 // Create a reader for listing databases (not database-specific)
682- $ reader = match ($ this ->source ) {
683- static ::SOURCE_API => new APIReader (new Databases ($ this ->client )),
684- static ::SOURCE_DATABASE => new DatabaseReader ($ this ->dbForProject , $ this ->getDatabaseDB ),
685- default => throw new \Exception ('Unknown source ' ),
686- };
672+ $ reader = $ this ->createReader ();
687673
688674 while (true ) {
689675 $ queries = [$ reader ->queryLimit ($ batchSize )];
@@ -712,17 +698,23 @@ private function exportDatabases(int $batchSize, array $resources = []): void
712698 $ response = $ reader ->listDatabases ($ queries );
713699
714700 foreach ($ response as $ database ) {
715- $ databaseType = $ database ['type ' ] ?? Resource::TYPE_DATABASE ;
716-
717- $ newDatabase = self ::getDatabase ($ databaseType , [
718- 'id ' => $ database ['$id ' ],
719- 'name ' => $ database ['name ' ],
720- 'createdAt ' => $ database ['$createdAt ' ],
721- 'updatedAt ' => $ database ['$updatedAt ' ],
722- 'type ' => $ databaseType ,
723- 'database ' => $ database ['database ' ]
724- ]);
725- $ databases [] = $ newDatabase ;
701+ $ databaseType = $ database ['type ' ];
702+ if ($ databaseType === Resource::TYPE_DATABASE_LEGACY || $ databaseType === Resource::TYPE_DATABASE_TABLESDB ) {
703+ $ databaseType = Resource::TYPE_DATABASE ;
704+ }
705+
706+ if (Resource::isSupported ($ databaseType , $ resources )) {
707+ $ newDatabase = self ::getDatabase ($ databaseType , [
708+ 'id ' => $ database ['$id ' ],
709+ 'name ' => $ database ['name ' ],
710+ 'createdAt ' => $ database ['$createdAt ' ],
711+ 'updatedAt ' => $ database ['$updatedAt ' ],
712+ 'type ' => $ databaseType ,
713+ 'database ' => $ database ['database ' ]
714+ ]);
715+ $ databases [] = $ newDatabase ;
716+
717+ }
726718 }
727719
728720 if (empty ($ databases )) {
@@ -752,12 +744,8 @@ private function exportEntities(string $databaseName, int $batchSize): void
752744 /** @var Database $database */
753745 $ lastTable = null ;
754746
755- // colections in the metadata
756- $ reader = match ($ this ->source ) {
757- static ::SOURCE_API => new APIReader (new Databases ($ this ->client )),
758- static ::SOURCE_DATABASE => new DatabaseReader ($ this ->dbForProject , $ this ->getDatabaseDB ),
759- default => throw new \Exception ('Unknown source ' ),
760- };
747+ // collections in the metadata
748+ $ reader = $ this ->createReader ();
761749
762750 while (true ) {
763751 $ queries = [$ reader ->queryLimit ($ batchSize )];
@@ -833,11 +821,7 @@ private function exportFields(int $batchSize): void
833821 foreach ($ tables as $ table ) {
834822 $ lastColumn = null ;
835823
836- $ reader = match ($ this ->source ) {
837- static ::SOURCE_API => new APIReader (new Databases ($ this ->client )),
838- static ::SOURCE_DATABASE => new DatabaseReader ($ this ->dbForProject , $ this ->getDatabaseDB ),
839- default => throw new \Exception ('Unknown source ' ),
840- };
824+ $ reader = $ this ->createReader ();
841825
842826 while (true ) {
843827 $ queries = [$ reader ->queryLimit ($ batchSize )];
@@ -1049,11 +1033,7 @@ private function exportIndexes(string $entityType, int $batchSize): void
10491033 $ lastIndex = null ;
10501034
10511035 // Create reader for this specific database
1052- $ reader = match ($ this ->source ) {
1053- static ::SOURCE_API => new APIReader (new Databases ($ this ->client )),
1054- static ::SOURCE_DATABASE => new DatabaseReader ($ this ->dbForProject , $ this ->getDatabaseDB ),
1055- default => throw new \Exception ('Unknown source ' ),
1056- };
1036+ $ reader = $ this ->createReader ();
10571037
10581038 while (true ) {
10591039 $ queries = [$ reader ->queryLimit ($ batchSize )];
@@ -1110,7 +1090,8 @@ private function exportRecords(string $entityName, int $batchSize): void
11101090 $ reader = match ($ this ->source ) {
11111091 static ::SOURCE_API => new APIReader (new Databases ($ this ->client )),
11121092 static ::SOURCE_DATABASE => new DatabaseReader (
1113- $ this ->dbForProject ,$ this ->getDatabaseDB
1093+ $ this ->dbForProject ,
1094+ $ this ->getDatabaseDB
11141095 ),
11151096 default => throw new \Exception ('Unknown source ' ),
11161097 };
@@ -1710,7 +1691,7 @@ private function exportTablesDB(int $batchSize, array $resources)
17101691
17111692 /**
17121693 * Export DocumentsDB databases (collections and documents)
1713- *
1694+ *
17141695 * @param int $batchSize
17151696 * @param array $resources
17161697 * @param array $documentsDBDatabases
@@ -1737,7 +1718,7 @@ private function exportDocumentsDB(int $batchSize, array $resources): void
17371718
17381719 try {
17391720 if (\in_array (Resource::TYPE_INDEX , $ resources )) {
1740- $ this ->exportIndexes (Collection::getName (),$ batchSize );
1721+ $ this ->exportIndexes (Collection::getName (), $ batchSize );
17411722 }
17421723 } catch (\Throwable $ e ) {
17431724 $ this ->addError (
0 commit comments