diff --git a/backend/alembic/versions/g1h2i3j4k5l6_add_product_messages.py b/backend/alembic/versions/g1h2i3j4k5l6_add_product_messages.py new file mode 100644 index 0000000..70a4b4d --- /dev/null +++ b/backend/alembic/versions/g1h2i3j4k5l6_add_product_messages.py @@ -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") diff --git a/backend/app/models/__init__.py b/backend/app/models/__init__.py index 5a393ec..87dcd1f 100644 --- a/backend/app/models/__init__.py +++ b/backend/app/models/__init__.py @@ -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", ] diff --git a/backend/app/models/message.py b/backend/app/models/message.py new file mode 100644 index 0000000..71102da --- /dev/null +++ b/backend/app/models/message.py @@ -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="留言时间", + )