51feae55ba
- 后端:FastAPI + SQLAlchemy + Alembic,7 张核心表迁移成功 - 前端:Next.js 16 + TailwindCSS 4 + 三端布局(投资人/创始人/Admin) - 数据库:PostgreSQL 16,7 张核心实体表(tenants/users/companies/monthly_reports/health_scores/risk_events/audit_logs) - Docker:docker-compose.yml + 前后端 Dockerfile - 测试:健康检查 4 个测试全部 GREEN - 文档:README/run.md/AGENTS.md/docs 体系完整
32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
"""审计日志模型。
|
|
|
|
全链路操作记录,保留 ≥ 6 月。
|
|
"""
|
|
|
|
import uuid
|
|
from datetime import datetime, timezone
|
|
|
|
from sqlalchemy import DateTime, ForeignKey, String, Text
|
|
from sqlalchemy.dialects.postgresql import JSONB, INET
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class AuditLog(Base):
|
|
"""审计日志。"""
|
|
|
|
__tablename__ = "audit_logs"
|
|
|
|
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
|
tenant_id: Mapped[str] = mapped_column(String(36), ForeignKey("tenants.id"), nullable=False, index=True)
|
|
user_id: Mapped[str | None] = mapped_column(String(36), ForeignKey("users.id"), nullable=True)
|
|
action: Mapped[str] = mapped_column(String(100), nullable=False, comment="操作类型:login/view/create/update/delete/export/ai_call")
|
|
resource_type: Mapped[str | None] = mapped_column(String(50), nullable=True, comment="资源类型")
|
|
resource_id: Mapped[str | None] = mapped_column(String(36), nullable=True, comment="资源 ID")
|
|
detail_json: Mapped[dict | None] = mapped_column(JSONB, nullable=True, comment="操作详情")
|
|
ip: Mapped[str | None] = mapped_column(INET, nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
|
|
)
|