- 新增 app/baked/algorithm|pipeline,非部署参数不再走 env;Settings 保留 DB/HTTP/RTSP/海康/百度/MinIO/Demo - 移除 init_db_schema 与 reload 配置;main 仅 check_database;start*.sh 在 uvicorn 前执行 alembic upgrade head - 依赖 psycopg[binary] 供 Alembic 同步 URL;alembic/env 注释与预发清单更新 - 撕段门控消费管线、各视频/语音/归档调用改为 baked - 百度环境变量仅 BAIDU_APP_ID、BAIDU_API_KEY、BAIDU_SECRET_KEY 与 BAIDU_* 超时/ASR;人脸脚本与 baidu_speech 文案同步 - 全量单测与 .env.example 更新;.gitignore 忽略 refs/(本地权重/视频不入库) Made-with: Cursor
62 lines
1.4 KiB
Python
62 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""清空本应用写入的 PostgreSQL 业务表(开发用;表结构保留)。
|
|
|
|
直接执行即可:``uv run python scripts/start_fresh.py``
|
|
|
|
``./start_fresh.sh`` 与 ``./start.sh`` 一致,仅在启动 uvicorn 前多执行本脚本。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import os
|
|
import sys
|
|
|
|
# 允许从任意 cwd 以 `uv run python scripts/start_fresh.py` 运行
|
|
_REPO_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
|
if _REPO_ROOT not in sys.path:
|
|
sys.path.insert(0, _REPO_ROOT)
|
|
|
|
from sqlalchemy import text
|
|
|
|
from app.config import settings
|
|
from app.database import engine
|
|
|
|
|
|
# 与 app/db/models.py 一致;有 FK 时子表排前面
|
|
_TABLES = (
|
|
"surgery_result_details",
|
|
"surgery_final_results",
|
|
"voice_confirmation_audits",
|
|
)
|
|
|
|
_TRUNCATE_SQL = text(
|
|
"TRUNCATE TABLE "
|
|
+ ", ".join(_TABLES)
|
|
+ " RESTART IDENTITY"
|
|
)
|
|
|
|
|
|
async def _run() -> None:
|
|
async with engine.begin() as conn:
|
|
await conn.execute(_TRUNCATE_SQL)
|
|
dsn = settings.sqlalchemy_database_url
|
|
safe = dsn
|
|
if "@" in dsn:
|
|
# 隐藏 user:pass
|
|
at = dsn.rfind("@")
|
|
if "://" in dsn:
|
|
parts = dsn.split("://", 1)
|
|
safe = f"{parts[0]}://***@{dsn[at + 1:]}"
|
|
print("已清空表:", ", ".join(_TABLES))
|
|
print("数据库:", safe)
|
|
|
|
|
|
def main() -> None:
|
|
asyncio.run(_run())
|
|
print("完成。")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|