qia-server/prisma/schema.prisma
ddshi fbff8cc230 feat: 添加SQLite本地数据库支持
- 移除Prisma中不支持SQLite的类型(Json、枚举)
- 使用String类型替代枚举值
- 更新Prisma schema适配SQLite
- 添加数据库初始化脚本scripts/init-db.js
- 更新数据库路径配置
- 添加sql.js依赖
- 删除旧的prisma.ts使用新的db.ts

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-29 16:33:55 +08:00

89 lines
2.4 KiB
Plaintext

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
// User model
model User {
id String @id @default(uuid())
email String @unique
password_hash String
nickname String?
created_at DateTime @default(now())
updated_at DateTime @updatedAt
// Relations
events Event[]
notes Note[]
conversations AICoachConversation[]
@@map("users")
}
// Event model (for both Anniversary and Reminder)
model Event {
id String @id @default(uuid())
user_id String
type String // 'anniversary' | 'reminder' (String for SQLite)
title String
content String? // Only for reminders
date DateTime // For anniversaries: the date; For reminders: the reminder date
is_lunar Boolean @default(false)
repeat_type String @default("none") // 'yearly' | 'monthly' | 'none' (String for SQLite)
is_holiday Boolean @default(false) // Only for anniversaries
is_completed Boolean @default(false) // Only for reminders
created_at DateTime @default(now())
updated_at DateTime @updatedAt
// Relations
user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
@@index([user_id])
@@index([type])
@@index([date])
@@map("events")
}
// Note model (for quick notes)
model Note {
id String @id @default(uuid())
user_id String
content String // HTML content from rich text editor
created_at DateTime @default(now())
updated_at DateTime @updatedAt
// Relations
user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
// One note per user (based on PRD - 便签编辑区)
@@unique([user_id])
@@map("notes")
}
// AI Conversation model
model AICoachConversation {
id String @id @default(uuid())
user_id String
message String
response String
parsed_data String? // AI parsed event data (JSON string for SQLite)
created_at DateTime @default(now())
// Relations
user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
@@index([user_id])
@@map("ai_coach_conversations")
}
// Note: Using String types instead of enums for SQLite compatibility
// Event type values: 'anniversary' | 'reminder'
// Repeat type values: 'yearly' | 'monthly' | 'none'