fix: 修两个 bug

1. ArticleRead.user_id 改 Integer(users.id 是 Integer,不是 BigInteger)
   alembic 0007 同样改 Integer
2. ArticleDetail.vue toggleRead 重复 catch 块导致 build 失败
   (edit 时新加的 catch 跟 toggleStar 残留的 catch 撞了)
This commit is contained in:
xiaji
2026-06-13 21:10:22 +08:00
parent 6c71ab2e79
commit 4ca05b8b7d
3 changed files with 5 additions and 7 deletions

View File

@@ -25,8 +25,8 @@ depends_on = None
def upgrade() -> None: def upgrade() -> None:
op.create_table( op.create_table(
"article_reads", "article_reads",
sa.Column("user_id", sa.BigInteger, nullable=False), sa.Column("user_id", sa.Integer, nullable=False), # users.id 是 Integer
sa.Column("article_id", sa.BigInteger, nullable=False), sa.Column("article_id", sa.BigInteger, nullable=False), # articles.id 是 BigInteger
sa.Column("read_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")), sa.Column("read_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
sa.PrimaryKeyConstraint("user_id", "article_id", name="pk_article_reads"), sa.PrimaryKeyConstraint("user_id", "article_id", name="pk_article_reads"),
sa.ForeignKeyConstraint( sa.ForeignKeyConstraint(

View File

@@ -9,12 +9,13 @@
注意: 注意:
- 删文章时 ondelete=CASCADE 自动清掉已读记录 - 删文章时 ondelete=CASCADE 自动清掉已读记录
- 这是和 bookmarks 并列的"用户行为" - 这是和 bookmarks 并列的"用户行为"
- user_id 是 Integer(users.id 是 Integer),article_id 是 BigInteger(articles.id 是 BigInteger)
""" """
from __future__ import annotations from __future__ import annotations
from datetime import datetime from datetime import datetime
from sqlalchemy import BigInteger, DateTime, ForeignKey, Index, func from sqlalchemy import BigInteger, DateTime, ForeignKey, Index, Integer, func
from sqlalchemy.orm import Mapped, mapped_column from sqlalchemy.orm import Mapped, mapped_column
from app.database import Base from app.database import Base
@@ -24,7 +25,7 @@ class ArticleRead(Base):
__tablename__ = "article_reads" __tablename__ = "article_reads"
user_id: Mapped[int] = mapped_column( user_id: Mapped[int] = mapped_column(
ForeignKey("users.id", ondelete="CASCADE"), primary_key=True Integer, ForeignKey("users.id", ondelete="CASCADE"), primary_key=True
) )
article_id: Mapped[int] = mapped_column( article_id: Mapped[int] = mapped_column(
BigInteger, BigInteger,

View File

@@ -73,9 +73,6 @@ async function toggleRead() {
article.value.is_read = wasRead article.value.is_read = wasRead
message.error(e?.response?.data?.title || '操作失败') message.error(e?.response?.data?.title || '操作失败')
} }
} catch (e: any) {
message.error(e?.response?.data?.title || '操作失败')
}
} }
function fmtTime(s?: string | null) { function fmtTime(s?: string | null) {