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