feat(testdata): 一键换库——history-test.db→history.db、原库留底 history-y.db(session 同理),-wal/-shm 随行,失败自动回滚;留底已存在则拒绝覆盖

This commit is contained in:
lianjianwei2024
2026-10-10 10:37:00 +08:00
parent 233a85d490
commit 1725ea3a8b
2 changed files with 58 additions and 0 deletions

View File

@@ -183,6 +183,17 @@ class H(BaseHTTPRequestHandler):
self._send(200, {"ok": True, "msg": "已对齐 %d 个批次" % n})
except Exception as e:
self._send(200, {"ok": False, "msg": str(e)})
elif self.path == "/api/switch":
dd = G.find_data_dir()
if not dd:
self._send(200, {"ok": False, "msg": "找不到数据目录"})
else:
try:
G.switch_dbs(dd, log=log)
self._send(200, {"ok": True,
"msg": "换库完成!现在点「启动造价审核.bat」即可查看测试数据。"})
except Exception as e:
self._send(200, {"ok": False, "msg": str(e)})
elif self.path == "/api/delete":
ok, msg = start_sub("delete", {})
self._send(200, {"ok": ok, "msg": msg})
@@ -314,6 +325,7 @@ history-test.db / session-test.db(首次自动从真实库克隆底子),<b
<div class="row">
<button id="bRun" onclick="doRun()">开始生成</button>
<button class="gray" onclick="doStop()">停止(软暂停)</button>
<button style="background:var(--ok)" onclick="doSwitch()">一键换库</button>
<button class="red" onclick="doDel()">删除全部测试数据</button>
<button class="gray" onclick="doAlign()">版本对齐</button>
<button class="gray" onclick="loadStats()">刷新统计</button>
@@ -343,6 +355,9 @@ async function doStop(){await post("/api/stop",{});}
async function doDel(){if(!confirm("确认真删除全部「测试」前缀的模拟数据?此操作不可恢复!"))return;
await post("/api/delete",{});poll();}
async function doAlign(){const r=await post("/api/align",{});alert(r.msg||"完成");}
async function doSwitch(){
if(!confirm("一键换库:测试库换上(history-test.db→history.db),原库留底为 history-y.db / session-y.db。\n\n请先关闭造价审核软件,否则文件占用会失败。继续?"))return;
const r=await post("/api/switch",{});alert(r.msg||"完成");loadStats();}
async function saveDir(which){
const b={};
if(which==="ref")b.ref_dir=document.getElementById("refdir").value;