按 docs/v2/05-implementation-plan.md §1 候选迁移表与 claude_use/T00 白名单, 从 55e2cdb 抽取 224 个文件(2.48 MB)到独立目录 F:/mini-OpenClaw-v2。 - 排除:凭据(.env/server-deploy.conf/旧DELIVERY.md)、运行数据(xingbang_data 等 4 个 SQLite)、依赖(venv/node_modules 符号链接)、归档(_backup*/test-evidence/ ori_file)、Office 临时文件 - 目标目录独立 git 仓库,初始恢复点;Gitea 远程与分支待 OQ-06 Q2 定案 - 未部署、未启动服务、未调用模型 Co-Authored-By: Claude Code <noreply@anthropic.com>
43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
"""Build the sanitized multi-table leasing database used by the local demo."""
|
|
import os
|
|
import sqlite3
|
|
from contextlib import closing
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
SCHEMA_PATH = ROOT / "fixtures" / "xingbang_demo" / "business_database.sql"
|
|
DEFAULT_PATH = ROOT / "xingbang_data" / "xingbang_business_demo.sqlite3"
|
|
|
|
|
|
def build_business_demo_database(target=DEFAULT_PATH, force=False):
|
|
target = Path(target).resolve()
|
|
if target.exists() and not force:
|
|
return target
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
temporary = target.with_name(target.name + ".building")
|
|
if temporary.exists():
|
|
temporary.unlink()
|
|
try:
|
|
with closing(sqlite3.connect(temporary)) as db:
|
|
db.executescript(SCHEMA_PATH.read_text(encoding="utf-8"))
|
|
result = db.execute("PRAGMA integrity_check").fetchone()[0]
|
|
if result != "ok":
|
|
raise RuntimeError("演示业务库完整性检查失败")
|
|
db.commit()
|
|
os.replace(temporary, target)
|
|
finally:
|
|
if temporary.exists():
|
|
temporary.unlink()
|
|
return target
|
|
|
|
|
|
def database_summary(target=DEFAULT_PATH):
|
|
target = Path(target).resolve()
|
|
with sqlite3.connect(target) as db:
|
|
tables = [row[0] for row in db.execute(
|
|
"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' ORDER BY name"
|
|
)]
|
|
counts = {table: db.execute(f'SELECT COUNT(*) FROM "{table}"').fetchone()[0] for table in tables}
|
|
return {"database": str(target), "tables": counts}
|