refactor(training): 培训数据层并入唯一总库 app.db(非运行态建表/种子,全列可空)
- 训练 ORM 模型改名回旧表名(accounts/events/bookings/tests/courses/policy_logs/plan_logs/survey_logs) 并全列可空(兼容按部分字段插入);alembic 0003 丢弃重建并入唯一总库。 - training/db.py 指向 app.db、移除运行时 init_db;main.py lifespan 移除 init_db。 - seed.py 增培训种子(超管账号/排期/在线课程, 幂等)。 - 验证(真实库 migrate+seed+TestClient):auth/me、admin/*、park/*、training /api/health|events|courses 全 200。
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
"""培训业务表并入唯一总库(accounts/events/bookings/tests/courses/policy_logs/plan_logs/survey_logs,全列可空)
|
||||
|
||||
Revision ID: 0003_training_tables
|
||||
Revises: 0002_park_screen_bind
|
||||
Create Date: 2026-08-24
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import os
|
||||
from alembic import op
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
||||
|
||||
revision = "0003_training_tables"
|
||||
down_revision = "0002_park_screen_bind"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
_TABLES = ["accounts", "events", "bookings", "tests", "courses", "policy_logs", "plan_logs", "survey_logs"]
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# 培训表并入 app.db;若此前残留旧表则丢弃后按当前(可空列)模型重建
|
||||
for t in _TABLES:
|
||||
try:
|
||||
op.drop_table(t)
|
||||
except Exception: # 表不存在则忽略
|
||||
pass
|
||||
from app.infrastructure.db import Base
|
||||
import app.infrastructure.models # noqa: F401
|
||||
Base.metadata.create_all(bind=op.get_bind())
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
for t in _TABLES:
|
||||
try:
|
||||
op.drop_table(t)
|
||||
except Exception:
|
||||
pass
|
||||
Reference in New Issue
Block a user