fix: 修复决策339老库补列顺序并撤除回填兼容逻辑
This commit is contained in:
@@ -70,17 +70,8 @@ def name_pre(s):
|
||||
"""模糊档前缀键:norm(s) 前 NAME_PRE_LEN 字。导入落列与查询取键**必须同走本函数**(口径不分叉)。"""
|
||||
return norm(s)[:NAME_PRE_LEN]
|
||||
|
||||
|
||||
def backfill_name_pre(con):
|
||||
"""老库回填 x_name_pre(决策 339):对前缀列为 NULL 的行按 Name 现算(幂等,探针跳过)。
|
||||
返回回填行数;由 api_server.migrate_name_pre 在启动时调用(建索引在 schema.sql+同处补)。"""
|
||||
rows = con.execute("SELECT id, Name FROM bills WHERE x_name_pre IS NULL").fetchall()
|
||||
if not rows:
|
||||
return 0
|
||||
con.executemany("UPDATE bills SET x_name_pre=? WHERE id=?",
|
||||
[(name_pre(r[1] or ""), r[0]) for r in rows])
|
||||
con.commit()
|
||||
return len(rows)
|
||||
# 决策 339 补记(主人令「不用兼容老的」):老库回填逻辑撤除——存量旧行 x_name_pre=NULL,
|
||||
# 模糊档对它们自然不命中(精确/次精确/字集三档不受影响),重导即新口径。
|
||||
|
||||
|
||||
SEARCH_BUDGET_S = 5.0 # ③ 独立检索扫描预算(秒)——超时中断降级,宁少结果不白等(主人拍板口径)
|
||||
|
||||
@@ -1978,15 +1978,17 @@ def _ensure_batch_schema():
|
||||
return
|
||||
try:
|
||||
c = sqlite3.connect(DB)
|
||||
# 决策 339 修复(主人令「不用兼容老的,快速修复」):**补列必须在 executescript 之前**——
|
||||
# schema.sql 里 `CREATE INDEX ... ON bills(x_name_pre)` 对还没补列的老库会 no such column,
|
||||
# executescript 中途炸掉且被下方 except 吞掉 → 后续补列全没跑 → 启动崩(2026-11-15 实录)。
|
||||
# 先 ALTER 补列(新空库 PRAGMA 无表自动跳过),再跑 schema.sql 就全程可过。
|
||||
_ensure_cols(c, "bills", [("x_name_pre", "TEXT")]) # 决策 339:模糊档前缀键(老库不加回填——存量旧行前缀 NULL,模糊档自然不命中,重导即新口径)
|
||||
c.executescript(io.open(SCHEMA_SQL, encoding="utf-8").read())
|
||||
# 对已存在的旧库补列(新建库时 PRAGMA 已含新列,这里会自动跳过)
|
||||
_ensure_cols(c, "bills", [("uw_id", "INTEGER"), ("div_id", "INTEGER"),
|
||||
("Quantity", "REAL"), ("Total", "REAL"),
|
||||
# 源文件备注(清单节点 Remark 属性,2026-10-08;只显示在「原数据」)
|
||||
("src_remark", "TEXT"),
|
||||
# 决策 339:模糊档前缀键(match.name_pre(Name))——老库补列,
|
||||
# 回填+建索引在 api_server.migrate_name_pre(schema.sql 之后跑才安全)
|
||||
("x_name_pre", "TEXT")])
|
||||
("src_remark", "TEXT")])
|
||||
_ensure_cols(c, "norms", [("Quantity", "REAL"), ("Total", "REAL"),
|
||||
# 规格 19:定额工程量系数(**GCL 口径** = 定额量÷历史GCL,
|
||||
# 导入时算好存库,采纳时直接取用生成 GCL*系数 公式;主人 2026-10-17 定)
|
||||
|
||||
@@ -313,17 +313,6 @@ def migrate_match_keys():
|
||||
con.commit()
|
||||
finally:
|
||||
con.close()
|
||||
# 决策 339:模糊档前缀键回填+建索引(列由 _ensure_batch_schema 补;回填要 match.name_pre 现算,
|
||||
# 必须在该列存在后跑——放 migrate_match_keys 之后,与 setkey 回填同一启动序列)
|
||||
con = sqlite3.connect(DB)
|
||||
try:
|
||||
nb = match.backfill_name_pre(con)
|
||||
if nb:
|
||||
print("迁移:bills 模糊档前缀键回填 %d 行(决策 339)" % nb, flush=True)
|
||||
con.execute("CREATE INDEX IF NOT EXISTS ix_bill_namepre ON bills(x_name_pre)")
|
||||
con.commit()
|
||||
finally:
|
||||
con.close()
|
||||
scon = sess.connect()
|
||||
try:
|
||||
if not _hash9_current(scon, "s_bills"):
|
||||
|
||||
Reference in New Issue
Block a user