From 18e8281b5803223204fe33e32900337f2ed4b3c8 Mon Sep 17 00:00:00 2001 From: ycggyao Date: Fri, 6 Dec 2024 15:52:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(backend):=20sqlserver=20=E4=BB=A5=E9=9B=86?= =?UTF-8?q?=E7=BE=A4=E4=B8=BA=E7=BB=B4=E5=BA=A6=E5=A4=84=E7=90=86rename=5F?= =?UTF-8?q?infos=20#8461?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sqlserver/sqlserver_data_migrate.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/dbm-ui/backend/ticket/builders/sqlserver/sqlserver_data_migrate.py b/dbm-ui/backend/ticket/builders/sqlserver/sqlserver_data_migrate.py index f85f285879..b3dccbf361 100644 --- a/dbm-ui/backend/ticket/builders/sqlserver/sqlserver_data_migrate.py +++ b/dbm-ui/backend/ticket/builders/sqlserver/sqlserver_data_migrate.py @@ -113,18 +113,18 @@ def __init__(self, rename_type, ticket: Ticket): def format_db_rename_infos(self, cluster_key, from_key, to_key): """填充db重命名信息""" - dbrename_infos: List[Dict[str, str]] = [] + dbrename_infos_dict = defaultdict(list) for info in self.ticket_data["infos"]: - dbrename_infos.extend( - [ - { - "cluster_id": info[cluster_key], - "rename_infos": [{"db_name": db[from_key], "target_db_name": db[to_key]}], - } - for db in info["rename_infos"] - if db.get(from_key) and db.get(to_key) - ] - ) + cluster_id = info[cluster_key] + for db in info["rename_infos"]: + if db.get(from_key) and db.get(to_key): + dbrename_infos_dict[cluster_id].append({"db_name": db[from_key], "target_db_name": db[to_key]}) + + # 以集群为维度 将字典转换为所需的列表格式 + dbrename_infos = [ + {"cluster_id": cluster_id, "rename_infos": rename_infos} + for cluster_id, rename_infos in dbrename_infos_dict.items() + ] return dbrename_infos def format_target_cluster_rename_infos(self):