feat: 产品协同留言板 — ProductMessage 模型 + API + 迁移
- 新增 ProductMessage 模型,挂载在 products.id(ON DELETE CASCADE)
- GET/POST /products/{id}/messages 接口
- 注册到 Alembic 自动发现
This commit is contained in:
@ -0,0 +1,33 @@
|
||||
"""add_product_messages
|
||||
|
||||
Revision ID: g1h2i3j4k5l6
|
||||
Revises: c9d0e1f2a3b4
|
||||
Create Date: 2026-08-10
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
revision: str = "g1h2i3j4k5l6"
|
||||
down_revision: Union[str, None] = "c9d0e1f2a3b4"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"product_messages",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
|
||||
sa.Column("product_id", postgresql.UUID(as_uuid=True),
|
||||
sa.ForeignKey("products.id", ondelete="CASCADE"),
|
||||
index=True, nullable=False),
|
||||
sa.Column("operator_id", sa.String(50), nullable=False),
|
||||
sa.Column("content", sa.Text, nullable=False),
|
||||
sa.Column("created_at", sa.DateTime, nullable=True),
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table("product_messages")
|
||||
@ -6,6 +6,7 @@ from app.models.task import Task, TaskRecord
|
||||
from app.models.task_log import TaskLog
|
||||
from app.models.notification import Notification
|
||||
from app.models.app_version import AppVersion
|
||||
from app.models.message import ProductMessage
|
||||
__all__ = [
|
||||
"Base",
|
||||
"ProductionOrder",
|
||||
@ -15,4 +16,5 @@ __all__ = [
|
||||
"TaskLog",
|
||||
"Notification",
|
||||
"AppVersion",
|
||||
"ProductMessage",
|
||||
]
|
||||
|
||||
32
backend/app/models/message.py
Normal file
32
backend/app/models/message.py
Normal file
@ -0,0 +1,32 @@
|
||||
"""产品协同留言板模型"""
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from sqlalchemy import String, Text, DateTime, ForeignKey
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.models.base import Base
|
||||
|
||||
|
||||
class ProductMessage(Base):
|
||||
__tablename__ = "product_messages"
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(
|
||||
UUID(as_uuid=True), primary_key=True, default=uuid.uuid4,
|
||||
)
|
||||
product_id: Mapped[uuid.UUID] = mapped_column(
|
||||
UUID(as_uuid=True),
|
||||
ForeignKey("products.id", ondelete="CASCADE"),
|
||||
index=True,
|
||||
nullable=False,
|
||||
comment="所属产品 ID",
|
||||
)
|
||||
operator_id: Mapped[str] = mapped_column(
|
||||
String(50), nullable=False, comment="留言人姓名或工号",
|
||||
)
|
||||
content: Mapped[str] = mapped_column(
|
||||
Text, nullable=False, comment="留言内容",
|
||||
)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime, default=datetime.utcnow, comment="留言时间",
|
||||
)
|
||||
Reference in New Issue
Block a user