diff --git a/dataherald/db_scanner/sqlalchemy.py b/dataherald/db_scanner/sqlalchemy.py index dd8305d2..2badd775 100644 --- a/dataherald/db_scanner/sqlalchemy.py +++ b/dataherald/db_scanner/sqlalchemy.py @@ -64,23 +64,28 @@ def refresh_tables( metadata: dict = None, ) -> list[TableDescription]: stored_tables = repository.find_by({"db_connection_id": str(db_connection_id)}) + stored_tables_list = [table.table_name for table in stored_tables] rows = [] for table_description in stored_tables: if table_description.table_name not in tables: table_description.status = TableDescriptionStatus.DEPRECATED.value rows.append(repository.save_table_info(table_description)) + else: + rows.append(TableDescription(**table_description.dict())) + for table in tables: - rows.append( - repository.save_table_info( - TableDescription( - db_connection_id=db_connection_id, - table_name=table, - status=TableDescriptionStatus.NOT_SCANNED.value, - metadata=metadata, + if table not in stored_tables_list: + rows.append( + repository.save_table_info( + TableDescription( + db_connection_id=db_connection_id, + table_name=table, + status=TableDescriptionStatus.NOT_SCANNED.value, + metadata=metadata, + ) ) ) - ) return rows @override