修改消息相关索引
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import Boolean, ForeignKey, String, Text
|
||||
from sqlalchemy import Boolean, ForeignKey, String, Text, Index
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.models.base import Base, TimestampMixin
|
||||
@@ -16,3 +16,7 @@ class Notification(Base, TimestampMixin):
|
||||
type: Mapped[str] = mapped_column(String(32), default="system")
|
||||
is_read: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
related_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
|
||||
__table_args__ = (
|
||||
Index('idx_notif_user_isread_created', 'user_id', 'is_read', 'created_at'),
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import String, ForeignKey
|
||||
from sqlalchemy import String, ForeignKey, Index, UniqueConstraint
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.models.base import Base, TimestampMixin
|
||||
@@ -12,3 +12,8 @@ class NotificationRead(Base, TimestampMixin):
|
||||
String(32), ForeignKey("notifications.id"), index=True
|
||||
)
|
||||
user_id: Mapped[str] = mapped_column(String(32), index=True)
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint('notification_id', 'user_id', name='uq_notif_read_user'),
|
||||
Index('idx_notif_read_user_notif', 'user_id', 'notification_id'),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user