qia-server/prisma/schema.prisma
ddshi 55627762e1 feat: complete backend API with JWT auth, events, notes, AI routes
- Add Express.js server with TypeScript
- Configure Prisma ORM with PostgreSQL schema
- Implement JWT authentication (register, login, logout, refresh)
- Add rate limiting for auth endpoints (10 attempts/15min)
- Password strength validation (8+ chars, uppercase, lowercase, number)
- Events CRUD API (anniversaries and reminders)
- Notes API (single note per user)
- AI parse endpoint with DeepSeek integration
- Security: Helmet, rate limiting, input validation, error handling
- Fix: JWT_SECRET environment variable validation

Code review: Architect approved
Tests: Build verified
2026-01-29 13:08:48 +08:00

97 lines
2.3 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 = "postgresql"
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 @updated_at
// 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 EventType // 'anniversary' | 'reminder'
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 RepeatType @default(none)
is_holiday Boolean @default(false) // Only for anniversaries
is_completed Boolean @default(false) // Only for reminders
created_at DateTime @default(now())
updated_at DateTime @updated_at
// 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 @db.Text // HTML content from rich text editor
created_at DateTime @default(now())
updated_at DateTime @updated_at
// 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 Json? // AI parsed event data
created_at DateTime @default(now())
// Relations
user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
@@index([user_id])
@@map("ai_coach_conversations")
}
// Enums
enum EventType {
anniversary
reminder
}
enum RepeatType {
yearly
monthly
none
}