async def merge_duplicate_name_blocks(
        self,
        parent_id: UUID,
        store_type: StoreType,
    ) -> list[tuple[list[Entity], Entity]]:
        """Merge entities that share identical names.

        Returns list of tuples: (original_entities, merged_entity)
        """
        duplicate_blocks = await self.get_duplicate_name_blocks(
            parent_id, store_type
        )
        merged_results: list[tuple[list[Entity], Entity]] = []

        for block in duplicate_blocks:
            # Create a new merged entity from the block
            merged_entity = await self._create_merged_entity(block)
            merged_results.append((block, merged_entity))

            table_name = self._get_entity_table_for_store(store_type)
            async with self.connection_manager.transaction():
                # Insert the merged entity
                new_id = await self._insert_merged_entity(
                    merged_entity, table_name
                )

                merged_entity.id = new_id

                # Get the old entity IDs
                old_ids = [str(entity.id) for entity in block]

                relationship_table = self.relationships_handler._get_relationship_table_for_store(
                    store_type
                )

                # Update relationships where old entities appear as subjects
                subject_update_query = f"""
                    UPDATE {self._get_table_name(relationship_table)}
                    SET subject_id = $1
                    WHERE subject_id = ANY($2::uuid[])
                    AND parent_id = $3
                """
                await self.connection_manager.execute_query(
                    subject_update_query, [new_id, old_ids, parent_id]
                )

                # Update relationships where old entities appear as objects
                object_update_query = f"""
                    UPDATE {self._get_table_name(relationship_table)}
                    SET object_id = $1
                    WHERE object_id = ANY($2::uuid[])
                    AND parent_id = $3
                """
                await self.connection_manager.execute_query(
                    object_update_query, [new_id, old_ids, parent_id]
                )

                # Delete the original entities
                delete_query = f"""
                    DELETE FROM {self._get_table_name(table_name)}
                    WHERE id = ANY($1::uuid[])
                """
                await self.connection_manager.execute_query(
                    delete_query, [old_ids]
                )

        return merged_results
Merge entities that share identical names.

        Returns list of tuples: (original_entities, merged_entity)
        
py/core/providers/database/graphs.py