refactor: prefix every table with its module
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.
This commit is contained in:
@@ -23,19 +23,19 @@ from app.schemas.paper import (
|
||||
SentenceRead,
|
||||
SentenceUpdate,
|
||||
)
|
||||
from app.schemas.paper_template import (
|
||||
PaperTemplateCreate,
|
||||
PaperTemplateListItem,
|
||||
PaperTemplateRead,
|
||||
PaperTemplateUpdate,
|
||||
from app.schemas.template import (
|
||||
TemplateCreate,
|
||||
TemplateListItem,
|
||||
TemplateRead,
|
||||
TemplateUpdate,
|
||||
TemplateFieldInput,
|
||||
TemplateFieldRead,
|
||||
)
|
||||
from app.schemas.section_field import (
|
||||
SectionFieldCreate,
|
||||
SectionFieldRead,
|
||||
SectionFieldRef,
|
||||
SectionFieldUpdate,
|
||||
from app.schemas.template_field_library import (
|
||||
TemplateFieldLibraryCreate,
|
||||
TemplateFieldLibraryRead,
|
||||
TemplateFieldLibraryRef,
|
||||
TemplateFieldLibraryUpdate,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
@@ -57,14 +57,14 @@ __all__ = [
|
||||
"SentenceUpdate",
|
||||
"BatchDeleteResult",
|
||||
"PageResult",
|
||||
"PaperTemplateCreate",
|
||||
"PaperTemplateListItem",
|
||||
"PaperTemplateRead",
|
||||
"PaperTemplateUpdate",
|
||||
"SectionFieldCreate",
|
||||
"SectionFieldRead",
|
||||
"SectionFieldRef",
|
||||
"SectionFieldUpdate",
|
||||
"TemplateCreate",
|
||||
"TemplateListItem",
|
||||
"TemplateRead",
|
||||
"TemplateUpdate",
|
||||
"TemplateFieldLibraryCreate",
|
||||
"TemplateFieldLibraryRead",
|
||||
"TemplateFieldLibraryRef",
|
||||
"TemplateFieldLibraryUpdate",
|
||||
"TemplateFieldInput",
|
||||
"TemplateFieldRead",
|
||||
"normalize_hex_color",
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
"""Request/response schemas for paper templates (模板管理)."""
|
||||
"""Request/response schemas for templates (模板管理)."""
|
||||
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from app.models.paper_template import PaperTemplate
|
||||
from app.models.template import Template
|
||||
from app.models.template_field import TemplateField
|
||||
from app.schemas.common import TypographyMixin
|
||||
|
||||
@@ -54,14 +54,14 @@ class TemplateFieldRead(TypographyMixin, BaseModel):
|
||||
)
|
||||
|
||||
|
||||
class PaperTemplateBase(BaseModel):
|
||||
class TemplateBase(BaseModel):
|
||||
"""Shared body of the create/update payloads."""
|
||||
|
||||
name: str = Field(min_length=1, max_length=255)
|
||||
abstract: str | None = None
|
||||
|
||||
|
||||
class PaperTemplateCreate(PaperTemplateBase):
|
||||
class TemplateCreate(TemplateBase):
|
||||
"""Payload for ``POST /templates``.
|
||||
|
||||
The field selection is free: any subset, any order, repeats allowed. The
|
||||
@@ -71,7 +71,7 @@ class PaperTemplateCreate(PaperTemplateBase):
|
||||
fields: list[TemplateFieldInput] = Field(default_factory=list)
|
||||
|
||||
|
||||
class PaperTemplateUpdate(BaseModel):
|
||||
class TemplateUpdate(BaseModel):
|
||||
"""Payload for ``PATCH /templates/{id}``.
|
||||
|
||||
``fields`` is a full replacement when present — omit it to leave the
|
||||
@@ -83,7 +83,7 @@ class PaperTemplateUpdate(BaseModel):
|
||||
fields: list[TemplateFieldInput] | None = None
|
||||
|
||||
|
||||
class PaperTemplateListItem(BaseModel):
|
||||
class TemplateListItem(BaseModel):
|
||||
"""A template as it appears in the list table — no field rows."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
@@ -96,7 +96,7 @@ class PaperTemplateListItem(BaseModel):
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
class PaperTemplateRead(BaseModel):
|
||||
class TemplateRead(BaseModel):
|
||||
"""A template with its outline, already ordered by ``sort``."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
@@ -111,7 +111,7 @@ class PaperTemplateRead(BaseModel):
|
||||
updated_at: datetime
|
||||
|
||||
@classmethod
|
||||
def from_model(cls, template: PaperTemplate) -> "PaperTemplateRead":
|
||||
def from_model(cls, template: Template) -> "TemplateRead":
|
||||
"""Build the response from a template and its placement rows."""
|
||||
return cls(
|
||||
id=template.id,
|
||||
+10
-10
@@ -1,4 +1,4 @@
|
||||
"""Request/response schemas for the section-field library (字段管理)."""
|
||||
"""Request/response schemas for the template-field library (字段管理)."""
|
||||
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
@@ -8,8 +8,8 @@ from pydantic import BaseModel, ConfigDict, Field
|
||||
from app.schemas.common import TypographyMixin
|
||||
|
||||
|
||||
class SectionFieldBase(TypographyMixin, BaseModel):
|
||||
"""Fields a client may set on a section field."""
|
||||
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.
|
||||
@@ -25,12 +25,12 @@ class SectionFieldBase(TypographyMixin, BaseModel):
|
||||
font_color: str = Field(default="#000000", max_length=32)
|
||||
|
||||
|
||||
class SectionFieldCreate(SectionFieldBase):
|
||||
"""Payload for ``POST /section-fields``."""
|
||||
class TemplateFieldLibraryCreate(TemplateFieldLibraryBase):
|
||||
"""Payload for ``POST /template-field-library``."""
|
||||
|
||||
|
||||
class SectionFieldUpdate(TypographyMixin, BaseModel):
|
||||
"""Payload for ``PATCH /section-fields/{id}`` — every part optional.
|
||||
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.
|
||||
@@ -42,8 +42,8 @@ class SectionFieldUpdate(TypographyMixin, BaseModel):
|
||||
font_color: str | None = Field(default=None, max_length=32)
|
||||
|
||||
|
||||
class SectionFieldRead(SectionFieldBase):
|
||||
"""A stored section field."""
|
||||
class TemplateFieldLibraryRead(TemplateFieldLibraryBase):
|
||||
"""A stored library entry."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
@@ -52,7 +52,7 @@ class SectionFieldRead(SectionFieldBase):
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
class SectionFieldRef(BaseModel):
|
||||
class TemplateFieldLibraryRef(BaseModel):
|
||||
"""How many templates currently place a field — used to explain a refusal."""
|
||||
|
||||
field_id: int
|
||||
Reference in New Issue
Block a user