diff --git a/dataherald/api/fastapi.py b/dataherald/api/fastapi.py index 0f608416..a59a4d4c 100644 --- a/dataherald/api/fastapi.py +++ b/dataherald/api/fastapi.py @@ -144,6 +144,10 @@ def scan_db( db_connection_repository = DatabaseConnectionRepository(self.storage) scanner = self.system.instance(Scanner) + rows = scanner.synchronizing( + scanner_request, + TableDescriptionRepository(self.storage), + ) database_connection_service = DatabaseConnectionService(scanner, self.storage) for schema, table_descriptions in data.items(): db_connection = db_connection_repository.find_by_id( @@ -156,11 +160,7 @@ def scan_db( background_tasks.add_task( async_scanning, scanner, database, table_descriptions, self.storage ) - return [ - TableDescriptionResponse(**row.dict()) - for _, table_descriptions in data.items() - for row in table_descriptions - ] + return [TableDescriptionResponse(**row.dict()) for row in rows] @override def create_database_connection( diff --git a/dataherald/db_scanner/sqlalchemy.py b/dataherald/db_scanner/sqlalchemy.py index 6d3a7733..72b26c0f 100644 --- a/dataherald/db_scanner/sqlalchemy.py +++ b/dataherald/db_scanner/sqlalchemy.py @@ -102,14 +102,14 @@ def synchronizing( scanner_request: ScannerRequest, repository: TableDescriptionRepository, ) -> list[TableDescription]: - # persist tables to be scanned rows = [] - for table in scanner_request.table_names: + for id in scanner_request.ids: + table_description = repository.find_by_id(id) rows.append( repository.save_table_info( TableDescription( - db_connection_id=scanner_request.db_connection_id, - table_name=table, + db_connection_id=table_description.db_connection_id, + table_name=table_description.table_name, status=TableDescriptionStatus.SYNCHRONIZING.value, metadata=scanner_request.metadata, )