28 lines
880 B
Python
28 lines
880 B
Python
|
|
"""收藏。"""
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from datetime import datetime
|
||
|
|
|
||
|
|
from sqlalchemy import DateTime, ForeignKey, UniqueConstraint, func
|
||
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
||
|
|
|
||
|
|
from app.database import Base
|
||
|
|
|
||
|
|
|
||
|
|
class Bookmark(Base):
|
||
|
|
__tablename__ = "bookmarks"
|
||
|
|
|
||
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
||
|
|
user_id: Mapped[int] = mapped_column(
|
||
|
|
ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True
|
||
|
|
)
|
||
|
|
article_id: Mapped[int] = mapped_column(
|
||
|
|
ForeignKey("articles.id", ondelete="CASCADE"), nullable=False, index=True
|
||
|
|
)
|
||
|
|
note: Mapped[str | None] = mapped_column()
|
||
|
|
created_at: Mapped[datetime] = mapped_column(
|
||
|
|
DateTime(timezone=True), server_default=func.now(), nullable=False
|
||
|
|
)
|
||
|
|
|
||
|
|
__table_args__ = (UniqueConstraint("user_id", "article_id", name="uq_bookmark_user_article"),)
|