feat(testdata): 面板新增「数据库资产总览」——打开即自动清点参考库/测试库全量家底(批次/清单/定额/工料机/附件/会话),只读连接,生成前后可对账
This commit is contained in:
42
release/testdata/gen_testdata.py
vendored
42
release/testdata/gen_testdata.py
vendored
@@ -1233,6 +1233,48 @@ def stats_of(dd):
|
||||
sc.close()
|
||||
return out
|
||||
|
||||
# ---------------- 数据库资产总览(两库全量家底,打开面板即看) ----------------
|
||||
|
||||
def totals_of(dd):
|
||||
"""参考库与测试库的全量资产计数(不区分 mock,只数行数)。
|
||||
缺文件的库返回 None。全部走只读连接,不碰写入。"""
|
||||
rh, th, rs, ts = db_paths(dd)
|
||||
|
||||
def h_totals(p):
|
||||
if not os.path.exists(p):
|
||||
return None
|
||||
c = sqlite3.connect("file:%s?mode=ro" % p.replace("\\", "/"), uri=True,
|
||||
timeout=15)
|
||||
c.execute("PRAGMA busy_timeout=15000")
|
||||
out = {}
|
||||
for t in ("batches", "bills", "norms", "norm_res", "lmes", "lme_lib",
|
||||
"prices", "attachments"):
|
||||
try:
|
||||
out[t] = c.execute("SELECT COUNT(*) FROM %s" % t).fetchone()[0]
|
||||
except Exception:
|
||||
out[t] = -1
|
||||
c.close()
|
||||
return out
|
||||
|
||||
def s_totals(p):
|
||||
if not os.path.exists(p):
|
||||
return None
|
||||
c = sqlite3.connect("file:%s?mode=ro" % p.replace("\\", "/"), uri=True,
|
||||
timeout=15)
|
||||
c.execute("PRAGMA busy_timeout=15000")
|
||||
out = {}
|
||||
for t in ("sessions", "s_bills", "s_norms", "s_lmes"):
|
||||
try:
|
||||
out[t] = c.execute("SELECT COUNT(*) FROM %s" % t).fetchone()[0]
|
||||
except Exception:
|
||||
out[t] = -1
|
||||
c.close()
|
||||
return out
|
||||
|
||||
return {"ref_h": h_totals(rh), "ref_s": s_totals(rs),
|
||||
"test_h": h_totals(th), "test_s": s_totals(ts)}
|
||||
|
||||
|
||||
# ---------------- 分块删除 ----------------
|
||||
|
||||
def delete_testdata(dd, keep_files=False, log=print):
|
||||
|
||||
Reference in New Issue
Block a user