@@ -138,9 +138,18 @@ def scan_db(
138
138
table_description = scanner_repository .find_by_id (id )
139
139
if not table_description :
140
140
raise Exception ("Table description not found" )
141
- if table_description .schema_name not in data .keys ():
142
- data [table_description .schema_name ] = []
143
- data [table_description .schema_name ].append (table_description )
141
+ if table_description .db_connection_id not in data .keys ():
142
+ data [table_description .db_connection_id ] = {}
143
+ if (
144
+ table_description .schema_name
145
+ not in data [table_description .db_connection_id ].keys ()
146
+ ):
147
+ data [table_description .db_connection_id ][
148
+ table_description .schema_name
149
+ ] = []
150
+ data [table_description .db_connection_id ][
151
+ table_description .schema_name
152
+ ].append (table_description )
144
153
145
154
db_connection_repository = DatabaseConnectionRepository (self .storage )
146
155
scanner = self .system .instance (Scanner )
@@ -149,17 +158,16 @@ def scan_db(
149
158
TableDescriptionRepository (self .storage ),
150
159
)
151
160
database_connection_service = DatabaseConnectionService (scanner , self .storage )
152
- for schema , table_descriptions in data .items ():
153
- db_connection = db_connection_repository .find_by_id (
154
- table_descriptions [0 ].db_connection_id
155
- )
156
- database = database_connection_service .get_sql_database (
157
- db_connection , schema
158
- )
161
+ for db_connection_id , schemas_and_table_descriptions in data .items ():
162
+ for schema , table_descriptions in schemas_and_table_descriptions .items ():
163
+ db_connection = db_connection_repository .find_by_id (db_connection_id )
164
+ database = database_connection_service .get_sql_database (
165
+ db_connection , schema
166
+ )
159
167
160
- background_tasks .add_task (
161
- async_scanning , scanner , database , table_descriptions , self .storage
162
- )
168
+ background_tasks .add_task (
169
+ async_scanning , scanner , database , table_descriptions , self .storage
170
+ )
163
171
return [TableDescriptionResponse (** row .dict ()) for row in rows ]
164
172
165
173
@override
0 commit comments