104 lines
2.7 KiB
Plaintext
104 lines
2.7 KiB
Plaintext
// This is your Prisma schema file
|
|
// CreaBook Database Schema with User Authentication and Data Persistence
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "sqlite"
|
|
}
|
|
|
|
// User model for authentication
|
|
model User {
|
|
id String @id @default(cuid())
|
|
email String @unique
|
|
password String // Hashed password
|
|
name String?
|
|
role String @default("USER")
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
books Book[]
|
|
coverDesigns CoverDesign[]
|
|
sessions Session[]
|
|
}
|
|
|
|
// Session model for JWT token management
|
|
model Session {
|
|
id String @id @default(cuid())
|
|
userId String
|
|
token String @unique
|
|
expiresAt DateTime
|
|
createdAt DateTime @default(now())
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
}
|
|
|
|
// Book model for storing user books
|
|
model Book {
|
|
id String @id @default(cuid())
|
|
userId String
|
|
title String
|
|
genre String
|
|
idea String
|
|
logline String?
|
|
outline Json? // Stores chapter outline structure
|
|
currentChapter Int @default(1)
|
|
coverId String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
chapters Chapter[]
|
|
characters Character[]
|
|
}
|
|
|
|
// Chapter model for storing chapter content
|
|
model Chapter {
|
|
id String @id @default(cuid())
|
|
bookId String
|
|
number Int
|
|
title String
|
|
summary String
|
|
content String?
|
|
isGenerated Boolean @default(false)
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([bookId, number])
|
|
}
|
|
|
|
// Character model for storing character details
|
|
model Character {
|
|
id String @id @default(cuid())
|
|
bookId String
|
|
name String
|
|
role String // protagonist, antagonist, supporting
|
|
traits String // JSON array stored as string
|
|
motivation String?
|
|
backstory String?
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
|
|
book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
|
|
}
|
|
|
|
// CoverDesign model for storing cover designs
|
|
model CoverDesign {
|
|
id String @id @default(cuid())
|
|
userId String
|
|
filename String
|
|
url String
|
|
prompt String?
|
|
genre String?
|
|
isGenerated Boolean @default(false)
|
|
width Int?
|
|
height Int?
|
|
createdAt DateTime @default(now())
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
}
|