docs: 品牌全量口径统一为「南方基金」+ 作废文档清理
1) 客服 Agent 四份交付文档 + 构建脚手架:品牌由包装占位 XX科技 / 旧名 南方财富 统一为南方基金(热线 400-889-8899 / 官网 nffund.com),系统名改为「智能服务系统」; 同步追加 §0.4 修订记录行,工程记录行保留原占位字面以支撑硬编码扫描验收。 2) 开发文档:清理 28 份已作废/残留文档(14 份移出归档 + 14 份仓库副本), 新增《文档规整方案与开发前待决事项-2026-09-17》。 3) 客服agent 四份交付文档首次纳入本分支。
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
"""表存在性审计:`baseline_generated.sql` 声明的表 vs MySQL 实际表。
|
||||
|
||||
与另两个工具互补:
|
||||
- `tools/audit_constraints.py`:唯一键 ↔ 文档基线、ORM 映射 ↔ 库列名;
|
||||
- `tools/schema_fingerprint.py`:字段、索引与外键的结构指纹;
|
||||
- 本脚本:表名集合与列存在性。
|
||||
|
||||
凭据来自 `.env` 的 `MYSQL_DSN`,不在脚本内硬编码口令。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from urllib.parse import unquote, urlparse
|
||||
|
||||
import pymysql
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
SQL_FILE = ROOT / "alembic" / "baseline_generated.sql"
|
||||
VERSIONS_DIR = ROOT / "alembic" / "versions"
|
||||
|
||||
|
||||
def expected_tables() -> set[str]:
|
||||
text = SQL_FILE.read_text(encoding="utf-8")
|
||||
tables = set(re.findall(
|
||||
r"CREATE TABLE\s+(?:IF NOT EXISTS\s+)?`?([A-Za-z0-9_]+)`?",
|
||||
text,
|
||||
flags=re.IGNORECASE,
|
||||
))
|
||||
for path in VERSIONS_DIR.glob("*.py"):
|
||||
tables.update(re.findall(
|
||||
r"CREATE TABLE\s+(?:IF NOT EXISTS\s+)?`?([A-Za-z0-9_]+)`?",
|
||||
path.read_text(encoding="utf-8"),
|
||||
flags=re.IGNORECASE,
|
||||
))
|
||||
return tables
|
||||
|
||||
|
||||
def mysql_connection() -> pymysql.Connection:
|
||||
from app.core.config import get_settings
|
||||
|
||||
parsed = urlparse(get_settings().mysql_dsn.replace("mysql+asyncmy://", "mysql+pymysql://"))
|
||||
return pymysql.connect(
|
||||
host=parsed.hostname or "127.0.0.1",
|
||||
port=parsed.port or 3306,
|
||||
user=unquote(parsed.username or ""),
|
||||
password=unquote(parsed.password or ""),
|
||||
database=(parsed.path or "/").lstrip("/"),
|
||||
charset="utf8mb4",
|
||||
)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
connection = mysql_connection()
|
||||
database = connection.db.decode() if isinstance(connection.db, bytes) else connection.db
|
||||
with connection.cursor() as cursor:
|
||||
cursor.execute("SELECT table_name FROM information_schema.tables WHERE table_schema=%s", (database,))
|
||||
actual = {row[0] for row in cursor.fetchall()} - {"alembic_version"}
|
||||
expected = expected_tables()
|
||||
missing = expected - actual
|
||||
unexpected = actual - expected
|
||||
if missing or unexpected:
|
||||
raise SystemExit(f"table mismatch missing={sorted(missing)} unexpected={sorted(unexpected)}")
|
||||
cursor.execute(
|
||||
"SELECT table_name, column_name FROM information_schema.columns WHERE table_schema=%s",
|
||||
(database,),
|
||||
)
|
||||
actual_columns: dict[str, set[str]] = {}
|
||||
for table, column in cursor.fetchall():
|
||||
actual_columns.setdefault(table, set()).add(column)
|
||||
for table in sorted(expected):
|
||||
if not actual_columns.get(table):
|
||||
raise SystemExit(f"missing columns for {table}")
|
||||
connection.close()
|
||||
print(f"schema audit passed: {len(expected)} business tables, no missing or unexpected tables")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user