a5f884f440
Two tables were named after the concept they came from rather than the module
they belong to, so the schema read as if the template tables were part of the
paper module. Renamed (data preserved, `RENAME TABLE` moves rows in place):
paper_template -> template the 模板 module
section_field -> template_field_library the 字段库 the 模板 module owns
The paper tables and `template_field` already followed the rule. The rename
carries through everything that named a module:
models Template, TemplateField, TemplateFieldLibrary
schemas Template*, TemplateFieldLibrary*
crud app/crud/template.py, app/crud/template_field_library.py
API /template-field-library (was /section-fields); handlers are now
named after library entries, which removes the ambiguity with
TemplateField — a placement, a different thing entirely
client src/api/templateFieldLibrary.ts
`paper_template_filed_sort` is deliberately untouched: it is a column of the
paper module, spelled as the feature was specified.
TiDB v8.5 with tidb_enable_foreign_key on — as this cluster runs — enforces
foreign keys rather than ignoring them, so the docs' "TiDB does not enforce
foreign keys" was wrong. Corrected, with what actually follows from it: the
rename was rehearsed (RENAME TABLE carries a referencing constraint along), the
API keeps checking first so a violation names the row instead of surfacing a
driver error, and the ORM cascades stay so behaviour does not depend on a
cluster setting.
Revision f27a1c6d9e04 verified both ways; 40 smoke checks, type-check and build
all pass.
61 lines
2.0 KiB
Python
61 lines
2.0 KiB
Python
"""Request/response schemas for the template-field library (字段管理)."""
|
|
|
|
from datetime import datetime
|
|
from decimal import Decimal
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field
|
|
|
|
from app.schemas.common import TypographyMixin
|
|
|
|
|
|
class TemplateFieldLibraryBase(TypographyMixin, BaseModel):
|
|
"""Fields a client may set on a library entry."""
|
|
|
|
#: Display name, numbering included — e.g. ``"1. Introduction"``. Stored
|
|
#: and rendered verbatim; the API never rewrites it.
|
|
name: str = Field(min_length=1, max_length=255)
|
|
|
|
#: Heading depth. 1 = "1.", 2 = "1.1", 3 = "1.1.1". Rendering hint only.
|
|
level: int = Field(default=1, ge=1, le=9)
|
|
|
|
#: Font size in points. Fractional because 五号 = 10.5pt.
|
|
font_size: Decimal = Field(default=Decimal("12.0"), gt=0, le=99)
|
|
|
|
#: ``#RRGGBB``. ``rgb(...)`` and shorthand forms are normalised on write.
|
|
font_color: str = Field(default="#000000", max_length=32)
|
|
|
|
|
|
class TemplateFieldLibraryCreate(TemplateFieldLibraryBase):
|
|
"""Payload for ``POST /template-field-library``."""
|
|
|
|
|
|
class TemplateFieldLibraryUpdate(TypographyMixin, BaseModel):
|
|
"""Payload for ``PATCH /template-field-library/{id}`` — every part optional.
|
|
|
|
The colour normaliser tolerates ``None`` here; the validator returns
|
|
non-strings untouched, so an omitted colour stays omitted.
|
|
"""
|
|
|
|
name: str | None = Field(default=None, min_length=1, max_length=255)
|
|
level: int | None = Field(default=None, ge=1, le=9)
|
|
font_size: Decimal | None = Field(default=None, gt=0, le=99)
|
|
font_color: str | None = Field(default=None, max_length=32)
|
|
|
|
|
|
class TemplateFieldLibraryRead(TemplateFieldLibraryBase):
|
|
"""A stored library entry."""
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
|
|
class TemplateFieldLibraryRef(BaseModel):
|
|
"""How many templates currently place a field — used to explain a refusal."""
|
|
|
|
field_id: int
|
|
field_name: str
|
|
template_count: int
|