feat: 添加用户关注功能
- 新增 Follow 表和 User.bio 字段 (Prisma schema)
- 创建 follow 模块 (action-service-repository)
- 新增 FollowButton/FollowStats/UserList 组件
- 用户页面显示 bio、粉丝/关注数、关注按钮
- 新增 /users/[username]/followers 和 following 页面
- 添加 en-US/zh-CN i18n 翻译
⚠️ 需要运行: prisma migrate dev --name add_follow_and_bio
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "user" ADD COLUMN "bio" TEXT;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "follows" (
|
||||
"id" TEXT NOT NULL,
|
||||
"follower_id" TEXT NOT NULL,
|
||||
"following_id" TEXT NOT NULL,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "follows_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "follows_follower_id_idx" ON "follows"("follower_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "follows_following_id_idx" ON "follows"("following_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "follows_follower_id_following_id_key" ON "follows"("follower_id", "following_id");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "follows" ADD CONSTRAINT "follows_follower_id_fkey" FOREIGN KEY ("follower_id") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "follows" ADD CONSTRAINT "follows_following_id_fkey" FOREIGN KEY ("following_id") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -17,12 +17,15 @@ model User {
|
||||
updatedAt DateTime @updatedAt
|
||||
displayUsername String?
|
||||
username String @unique
|
||||
bio String?
|
||||
accounts Account[]
|
||||
dictionaryLookUps DictionaryLookUp[]
|
||||
folders Folder[]
|
||||
folderFavorites FolderFavorite[]
|
||||
sessions Session[]
|
||||
translationHistories TranslationHistory[]
|
||||
followers Follow[] @relation("UserFollowers")
|
||||
following Follow[] @relation("UserFollowing")
|
||||
|
||||
@@map("user")
|
||||
}
|
||||
@@ -198,3 +201,18 @@ model TranslationHistory {
|
||||
@@index([translatedText, sourceLanguage, targetLanguage])
|
||||
@@map("translation_history")
|
||||
}
|
||||
|
||||
model Follow {
|
||||
id String @id @default(cuid())
|
||||
followerId String @map("follower_id")
|
||||
followingId String @map("following_id")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
|
||||
follower User @relation("UserFollowers", fields: [followerId], references: [id], onDelete: Cascade)
|
||||
following User @relation("UserFollowing", fields: [followingId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([followerId, followingId])
|
||||
@@index([followerId])
|
||||
@@index([followingId])
|
||||
@@map("follows")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user