From 8be4e8f9400ecdbea2c64e1fd240753888d33dea Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 9 Sep 2026 16:53:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(dsync):=20dry-run=20=E9=A2=84=E6=BC=94?= =?UTF-8?q?=E6=9F=A5=E4=B8=BB=E9=94=AE=E5=AD=98=E5=9C=A8=E6=80=A7=E7=BB=99?= =?UTF-8?q?=E5=87=86=E7=A1=AE=E6=96=B0=E5=A2=9E/=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E9=A2=84=E4=BC=B0=E2=80=94=E2=80=94=E5=8E=9F=E5=85=88=E4=B8=80?= =?UTF-8?q?=E5=BE=8B=E7=AE=97=E6=96=B0=E5=A2=9E,=E5=B9=82=E7=AD=89?= =?UTF-8?q?=E9=87=8D=E5=AF=BC=E6=97=B6=E9=A2=84=E4=BC=B0=E8=99=9A=E9=AB=98?= =?UTF-8?q?=E8=AF=AF=E5=AF=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/dsync.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/deploy/dsync.py b/deploy/dsync.py index a04c100..8f6732d 100644 --- a/deploy/dsync.py +++ b/deploy/dsync.py @@ -303,7 +303,18 @@ def cmd_import(pkg_file, dry_run=False): stats["org_skipped"] += 1 continue if dry_run: - n_i += 1 + # 预演也查存在性,给出准确的新增/更新预估 + ex = False + if pk: + where = " AND ".join("`%s`=%%s" % c for c in pk) + with conn.cursor() as cur: + cur.execute("SELECT 1 FROM `%s` WHERE %s LIMIT 1" % (tbl, where), + tuple(str(row.get(c, "")) for c in pk)) + ex = cur.fetchone() is not None + if ex: + n_u += 1 + else: + n_i += 1 continue res = upsert_row(conn, tbl, pk, row, tcols) stats[res if res in stats else "skipped"] += 1