Epic 1, Story 1.4: Database Schema Definition with Prisma
- Installed Prisma and @prisma/client in backend/ directory - Initialized Prisma with PostgreSQL provider (Prisma 7.x) - Created prisma/schema.prisma with Book and ReadingLog models - Configured prisma.config.ts with DATABASE_URL from environment - Added .gitignore for Prisma-generated files Book model includes: - All required fields (id, title, author, totalPages, coverUrl, deadlineDate, isPrimary, status) - Timestamps (createdAt, updatedAt) - Indexes on deadlineDate and status for query performance - One-to-many relationship with ReadingLog ReadingLog model includes: - All required fields (id, bookId, logDate, currentPage) - Timestamps (createdAt, updatedAt) - Foreign key relationship to Book with cascade delete - Unique constraint on (bookId, logDate) - one entry per book per day - Indexes on bookId and logDate for query performance All acceptance criteria met: ✅ Prisma installed in backend/ ✅ Initialized with PostgreSQL provider ✅ schema.prisma defines Book and ReadingLog models ✅ Appropriate indexes for performance ✅ One-to-many relationship defined ✅ Unique constraint ensures one log entry per book per day Schema validated with npx prisma format 🤖 Generated with Claude Code (https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
27802f4bf3
commit
bed53dbbd3
5
backend/.gitignore
vendored
Normal file
5
backend/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
node_modules
|
||||
# Keep environment variables out of version control
|
||||
.env
|
||||
|
||||
/src/generated/prisma
|
||||
897
backend/package-lock.json
generated
897
backend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -13,11 +13,13 @@
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@prisma/client": "^7.1.0",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^17.2.3",
|
||||
"express": "^5.2.1",
|
||||
"express-validator": "^7.3.1",
|
||||
"helmet": "^8.1.0"
|
||||
"helmet": "^8.1.0",
|
||||
"prisma": "^7.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^9.39.1",
|
||||
|
||||
14
backend/prisma.config.ts
Normal file
14
backend/prisma.config.ts
Normal file
@ -0,0 +1,14 @@
|
||||
// This file was generated by Prisma and assumes you have installed the following:
|
||||
// npm install --save-dev prisma dotenv
|
||||
import "dotenv/config";
|
||||
import { defineConfig, env } from "prisma/config";
|
||||
|
||||
export default defineConfig({
|
||||
schema: "prisma/schema.prisma",
|
||||
migrations: {
|
||||
path: "prisma/migrations",
|
||||
},
|
||||
datasource: {
|
||||
url: env("DATABASE_URL"),
|
||||
},
|
||||
});
|
||||
43
backend/prisma/schema.prisma
Normal file
43
backend/prisma/schema.prisma
Normal file
@ -0,0 +1,43 @@
|
||||
// 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"
|
||||
}
|
||||
|
||||
model Book {
|
||||
id Int @id @default(autoincrement())
|
||||
title String @db.VarChar(500)
|
||||
author String? @db.VarChar(500)
|
||||
totalPages Int
|
||||
coverUrl String? @db.VarChar(1000)
|
||||
deadlineDate DateTime @db.Date
|
||||
isPrimary Boolean @default(false)
|
||||
status String @default("reading") @db.VarChar(50)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
readingLogs ReadingLog[]
|
||||
|
||||
@@index([deadlineDate])
|
||||
@@index([status])
|
||||
}
|
||||
|
||||
model ReadingLog {
|
||||
id Int @id @default(autoincrement())
|
||||
bookId Int
|
||||
logDate DateTime @db.Date
|
||||
currentPage Int
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
book Book @relation(fields: [bookId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([bookId, logDate])
|
||||
@@index([bookId])
|
||||
@@index([logDate])
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user