name: db description: Manage the Ghostfolio PostgreSQL database - migrations, schema, seeding, and Prisma operations disable-model-invocation: true allowed-tools: Bash, Read argument-hint: "[setup|migrate|seed|push|studio|status|reset|schema]"
Ghostfolio Database Manager
Manage the PostgreSQL database via Prisma ORM. Schema is defined at prisma/schema.prisma with 18 models and 108 migrations.
Current Schema Info
!cd /home/james-allen/Projects/ghostfolio && head -5 prisma/schema.prisma 2>/dev/null || echo "Schema not found"
Commands
Based on $ARGUMENTS:
setup (default if no argument)
Full database initialization (schema push + seed):
cd /home/james-allen/Projects/ghostfolio && npm run database:setup
This runs prisma db push followed by prisma db seed.
migrate
Run pending database migrations:
cd /home/james-allen/Projects/ghostfolio && npm run database:migrate
This runs prisma migrate deploy to apply all pending migrations.
seed
Seed the database with initial data (creates EMERGENCY_FUND and EXCLUDE_FROM_ANALYSIS tags):
cd /home/james-allen/Projects/ghostfolio && npm run database:seed
push
Push current schema to database without creating a migration (for prototyping):
cd /home/james-allen/Projects/ghostfolio && npm run database:push
Warning: This may reset data if schema changes are destructive.
studio
Open Prisma Studio (web-based database GUI):
cd /home/james-allen/Projects/ghostfolio && npm run database:gui
Opens at http://localhost:5555.
status
Check database connection and migration status:
cd /home/james-allen/Projects/ghostfolio && npx prisma migrate status
reset
Destructive - Reset the database completely (drop all data, re-apply schema, re-seed):
cd /home/james-allen/Projects/ghostfolio && npx prisma migrate reset
Always confirm with the user before running this.
schema
Read and display the current Prisma schema, highlighting models, enums, and relationships:
- Read
prisma/schema.prisma - Summarize: list all models with their field counts
- List all enums with their values
- Show key relationships
validate
Validate the Prisma schema:
cd /home/james-allen/Projects/ghostfolio && npm run database:validate-schema
format
Format the Prisma schema file:
cd /home/james-allen/Projects/ghostfolio && npm run database:format-schema
Key Database Models
- User - Core entity, all data cascades from here
- Account - Brokerage accounts (composite PK: id + userId)
- Order - Activities (BUY, SELL, DIVIDEND, FEE, INTEREST, LIABILITY)
- SymbolProfile - Asset metadata (unique on dataSource + symbol)
- MarketData - Historical prices (unique on dataSource + date + symbol)
Environment
Database connection is configured via DATABASE_URL in .env:
postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/${POSTGRES_DB}