feat: add stock database with prisma for portfolio persistence
- Initialize Prisma with SQLite and Stock model - Create database service layer with singleton client - Add API routes for stock CRUD operations - Integrate database with analyze page to persist ticker entries - Add Playwright tests for stock database functionality
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
# Prisma Stock Model Implementation Spec
|
||||
|
||||
## Goal
|
||||
Initialize Prisma ORM with SQLite database and create a Stock model to persist manually added stock tickers in the AITrader analyze route.
|
||||
|
||||
## Architecture
|
||||
- **ORM**: Prisma with SQLite datasource
|
||||
- **Database file**: `prisma/dev.db`
|
||||
- **Model**: `Stock` with id, ticker, optional notes, and timestamps
|
||||
- **Integration**: API routes for CRUD operations, integrated with analyze.tsx
|
||||
|
||||
## Design Decisions
|
||||
|
||||
### Stock Model Schema
|
||||
```prisma
|
||||
model Stock {
|
||||
id String @id @default(cuid())
|
||||
ticker String @unique
|
||||
notes String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
```
|
||||
|
||||
**Rationale for `notes` field**: Included for future extensibility (user notes on watched stocks). Nullable to avoid breaking changes.
|
||||
|
||||
### Implementation Approach
|
||||
- Single migration (`init`) for all model fields
|
||||
- SQLite for development simplicity (matches plan)
|
||||
- Prisma client singleton pattern for React Router 7 compatibility
|
||||
|
||||
## Files to Create/Modify
|
||||
|
||||
### Task 1: Initialize Prisma
|
||||
- `prisma/schema.prisma` - Prisma schema with Stock model
|
||||
- `prisma/dev.db` - SQLite database (generated)
|
||||
- `prisma/migrations/..._init/migration.sql` - Initial migration (generated)
|
||||
|
||||
## Success Criteria
|
||||
1. `prisma/schema.prisma` exists with valid Stock model
|
||||
2. `npx prisma generate` completes without errors
|
||||
3. `npx prisma migrate dev --name init` creates `prisma/dev.db`
|
||||
4. Git commit created with prisma/ changes
|
||||
|
||||
## Dependencies to Install
|
||||
- `prisma` (dev dependency)
|
||||
- `@prisma/client` (runtime dependency)
|
||||
Reference in New Issue
Block a user