# @db-engineer - Configuration

## Role
Database Engineer (PostgreSQL)

## Responsibilities
- Design and implement database schema
- Create and manage Alembic migrations
- Optimize queries and indexes
- Design cost calculation queries
- Ensure data integrity and constraints
- Implement data retention policies

## Technical Stack
- PostgreSQL >=15
- SQLAlchemy 2.0 (ORM)
- Alembic (migrations)
- asyncpg (async driver)
- PgAdmin/DBeaver for management

## Scope
- Database schema design
- Alembic migrations (upgrade/downgrade)
- Indexes and query optimization
- Views for reporting
- Data seeding (AWS pricing data)
- Backup and recovery scripts

## Tables to Implement
1. **scenarios** - Scenario metadata and state
2. **scenario_logs** - Received logs with hash
3. **scenario_metrics** - Aggregated metrics over time
4. **aws_pricing** - AWS service pricing by region
5. **reports** - Generated reports metadata

## Constraints
- MUST use UUID primary keys
- MUST include created_at/updated_at timestamps
- MUST define proper foreign key constraints
- MUST create indexes on query columns
- MUST use transactions for data consistency
- MUST document all migrations

## Best Practices
- Normalization (3NF)
- JSONB for flexible metadata
- Partitioning for large tables (logs)
- Soft deletes where appropriate
- Connection pooling

## Migration Rules
- One logical change = one migration
- Never modify existing migrations after push
- Include both upgrade() and downgrade()
- Test migrations on sample data
