Analyze database design and create a database optimization plan
Analyzes database schemas and queries to create a comprehensive optimization plan with actionable recommendations.
/plugin marketplace add dgriffith/bad-daves-robot-army/plugin install dgriffith-bad-daves-robot-army@dgriffith/bad-daves-robot-armyUsing @agent-database-designer prepare a database review report. You must analyze database schemas, query patterns, and data architecture in the codebase and create a comprehensive plan WITHOUT making any changes.
The user invoked: /database-review {optional_scope}
Valid scopes:
git status and git diff)git log and git diff)gh pr view and gh pr diff)If scope is "current changes":
git status to identify changed filesgit diff to see uncommitted changesIf scope is "recent changes":
git log --oneline -10 to see recent commitsgit diff HEAD~5..HEAD or appropriate rangeIf scope starts with "PR":
gh pr view {number} to get PR detailsgh pr diff {number} to get the changesIf scope is a path:
If no scope provided:
Schema Design Review
Query Performance Analysis
Data Architecture Assessment
Create a markdown file at /reports/database-review-{timestamp}.md with:
# Database Review Plan
Generated: {timestamp}
Scope: {full_path_or_entire_project}
## Executive Summary
Brief overview of database architecture health and critical findings
## Database Design Findings
### Critical Issues (Data Integrity Risk)
- [ ] Missing foreign key constraints: Tables X-Y
- [ ] No primary key: Table Z
- [ ] Inefficient data types: Column A using TEXT for IDs
### High Priority Issues
- [ ] N+1 queries: In service B
- [ ] Missing indexes: Slow queries on C
- [ ] Denormalization needed: Performance bottleneck D
### Medium Priority Issues
- [ ] Inconsistent naming: Mixed conventions
- [ ] Unused indexes: Maintenance overhead
- [ ] Missing constraints: Data validation gaps
## Current Database Assessment
### Schema Overview
- Database type: PostgreSQL/MySQL/MongoDB/etc
- Tables/Collections: X
- Total size: Y GB
- Growth rate: Z GB/month
- Query volume: N/second
### Performance Metrics
- Average query time: X ms
- Slow queries: Y per hour
- Connection pool usage: Z%
- Cache hit ratio: N%
## Database Improvement Plan
### Immediate Actions (1-3 days)
1. Add missing indexes for slow queries
2. Fix N+1 query problems
3. Add critical constraints
### Short-term Improvements (1-2 weeks)
1. Optimize complex queries
2. Implement query caching
3. Normalize/denormalize as needed
### Long-term Transformations (2-6 weeks)
1. Implement partitioning strategy
2. Add read replicas
3. Redesign problem areas
## Schema Optimization
### Normalization Analysis
- Current normal form: Assessment
- Over-normalization issues: List
- Under-normalization issues: List
- Recommended changes: Details
### Data Type Optimization
- [ ] VARCHAR(255) → Appropriate sizes
- [ ] TEXT → VARCHAR where applicable
- [ ] BIGINT → INT where sufficient
- [ ] Timestamp precision adjustments
## Indexing Strategy
### Missing Indexes
```sql
-- High impact indexes needed
CREATE INDEX idx_table_columns ON table(column1, column2);
CREATE INDEX idx_table2_column ON table2(column) WHERE condition;
-- Current slow query
SELECT * FROM large_table WHERE unindexed_column = ?
-- Optimized version
SELECT needed_columns FROM large_table
WHERE indexed_column = ?
LIMIT appropriate_number
Remember: DO NOT make any changes. Only analyze and report.
---
## CRITICAL: Report Generation
**YOU MUST CREATE THE REPORT FILE.** This is not optional.
### Final Steps (MANDATORY)
1. **Create the report file** using the Write tool at the specified path:
- Path format: `/reports/{command-name}-{scope}-{timestamp}.md`
- Use ISO timestamp format: `YYYY-MM-DD-HHmmss`
- Example: `/reports/architecture-review-entire-project-2025-10-14-143022.md`
2. **Fill in ALL sections** of the report template
- Do not leave placeholder text
- Provide specific, actionable findings
- Include file paths and line numbers where relevant
3. **Confirm completion** by telling the user:
- "Report saved to: [full path]"
- Brief summary of key findings
- Next steps or how to use the report
### Common Mistakes to Avoid
❌ **DON'T**: Just summarize findings in the chat
❌ **DON'T**: Say "I'll create a report" without actually doing it
❌ **DON'T**: Leave sections incomplete or with placeholders
❌ **DON'T**: Forget to use the Write tool
✅ **DO**: Always use the Write tool to create the markdown file
✅ **DO**: Fill in every section with real findings
✅ **DO**: Provide the full path to the user when done
✅ **DO**: Include actionable recommendations
### Verification Checklist
Before responding to the user, verify:
- [ ] Report file created with Write tool
- [ ] All template sections filled in
- [ ] Specific findings with file references
- [ ] Actionable recommendations included
- [ ] Timestamp in filename
- [ ] Full path provided to user
**Remember**: The report is the primary deliverable. The chat summary is secondary.