feat: 新增鉴权
This commit is contained in:
+77
-15
@@ -1,7 +1,5 @@
|
||||
// This is your Prisma schema file,
|
||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||
|
||||
// Get a free hosted Postgres database in seconds: `npx create-db`
|
||||
// prisma/schema.prisma - OCS 答题服务数据库 schema
|
||||
// 包含 Better Auth 认证表(User, Session, Account, Verification)和业务表(QaRecord)
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client"
|
||||
@@ -12,18 +10,82 @@ datasource db {
|
||||
provider = "mysql"
|
||||
}
|
||||
|
||||
// Better Auth 标准用户表
|
||||
// apiToken 由服务端注册 hook 生成,供 OCS 油猴脚本跨域身份验证
|
||||
model User {
|
||||
id Int @id @default(autoincrement())
|
||||
email String @unique
|
||||
name String?
|
||||
posts Post[]
|
||||
id String @id
|
||||
name String
|
||||
email String @unique
|
||||
emailVerified Boolean
|
||||
image String?
|
||||
createdAt DateTime
|
||||
updatedAt DateTime
|
||||
apiToken String? @unique
|
||||
sessions Session[]
|
||||
accounts Account[]
|
||||
qaRecords QaRecord[]
|
||||
|
||||
@@map("user")
|
||||
}
|
||||
|
||||
model Post {
|
||||
id Int @id @default(autoincrement())
|
||||
title String
|
||||
content String?
|
||||
published Boolean @default(false)
|
||||
author User @relation(fields: [authorId], references: [id])
|
||||
authorId Int
|
||||
// Better Auth 会话表
|
||||
model Session {
|
||||
id String @id
|
||||
expiresAt DateTime
|
||||
token String @unique
|
||||
createdAt DateTime
|
||||
updatedAt DateTime
|
||||
ipAddress String?
|
||||
userAgent String?
|
||||
userId String
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@map("session")
|
||||
}
|
||||
|
||||
// Better Auth 账号表(用于邮密和 OAuth Provider 关联)
|
||||
model Account {
|
||||
id String @id
|
||||
accountId String
|
||||
providerId String
|
||||
userId String
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
accessToken String?
|
||||
refreshToken String?
|
||||
idToken String? @db.Text
|
||||
accessTokenExpiresAt DateTime?
|
||||
refreshTokenExpiresAt DateTime?
|
||||
scope String?
|
||||
password String?
|
||||
createdAt DateTime
|
||||
updatedAt DateTime
|
||||
|
||||
@@map("account")
|
||||
}
|
||||
|
||||
// Better Auth 邮箱验证令牌表
|
||||
model Verification {
|
||||
id String @id
|
||||
identifier String
|
||||
value String
|
||||
expiresAt DateTime
|
||||
createdAt DateTime?
|
||||
updatedAt DateTime?
|
||||
|
||||
@@map("verification")
|
||||
}
|
||||
|
||||
// 用户问答记录,按用户隔离存储
|
||||
// search 接口在拿到有效 session 或 apiToken 后写入,与当前登录用户绑定
|
||||
model QaRecord {
|
||||
id String @id @default(cuid())
|
||||
userId String
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
question String @db.Text
|
||||
type String
|
||||
options String? @db.Text
|
||||
answer String? @db.Text
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@map("qa_record")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user