xxy 43f3e0b746 Initial commit
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-05 18:41:06 +08:00

69 lines
3.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
database/models.py
ORM 模型,与远程 MySQLeval_report 库)现有表结构一致:
- report_templates 模板
- report_template_sections 模板章节(目录 + 声明)
- report_section_references 章节参考范文(章节内容入库目标)
"""
from __future__ import annotations
from datetime import datetime
from typing import Optional
from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, String, Text
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
class Base(DeclarativeBase):
pass
class ReportTemplate(Base):
__tablename__ = "report_templates"
id: Mapped[str] = mapped_column(String(64), primary_key=True)
name: Mapped[str] = mapped_column(String(255), nullable=False)
description: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
is_default: Mapped[bool] = mapped_column(Boolean, default=False)
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
updated_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
class ReportTemplateSection(Base):
__tablename__ = "report_template_sections"
id: Mapped[str] = mapped_column(String(64), primary_key=True)
template_id: Mapped[str] = mapped_column(
ForeignKey("report_templates.id", ondelete="CASCADE"), nullable=False
)
section_key: Mapped[str] = mapped_column(String(64), nullable=False)
section_title: Mapped[str] = mapped_column(String(255), nullable=False)
# 本模块语义section_prompt 即为该目录生成的"声明"
section_prompt: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
section_output_contract: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
section_order: Mapped[int] = mapped_column(Integer, default=0)
examples: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
updated_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
class ReportSectionReference(Base):
"""章节参考范文(章节内容入库目标,格式与远程 MySQL 现有表一致)。"""
__tablename__ = "report_section_references"
id: Mapped[str] = mapped_column(String(64), primary_key=True)
# 关联模板(与 report_template_sections.template_id 一致);历史数据可能为空
template_id: Mapped[Optional[str]] = mapped_column(
ForeignKey("report_templates.id", ondelete="CASCADE"), nullable=True, index=True
)
source_file: Mapped[str] = mapped_column(String(255), nullable=False)
section_key: Mapped[str] = mapped_column(String(64), nullable=False)
section_title: Mapped[str] = mapped_column(String(255), nullable=False)
section_order: Mapped[int] = mapped_column(Integer, default=0)
content: Mapped[str] = mapped_column(Text, nullable=False)
created_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
updated_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)