Commit Graph

3 Commits

Author SHA1 Message Date
Luca Sacchi Ricciardi
abe9fc166b feat(migrations): T11 setup Alembic and initial schema migration
- Initialize Alembic with alembic init alembic
- Configure alembic.ini to use DATABASE_URL from environment
- Configure alembic/env.py to import Base and models metadata
- Generate initial migration: c92fc544a483_initial_schema
- Migration creates all 4 tables: users, api_keys, api_tokens, usage_stats
- Migration includes all indexes, constraints, and foreign keys
- Test upgrade/downgrade cycle works correctly

Alembic commands:
- alembic upgrade head
- alembic downgrade -1
- alembic revision --autogenerate -m 'message'

Tests: 13 migration tests pass
2026-04-07 11:14:45 +02:00
Luca Sacchi Ricciardi
ea198e8b0d feat(models): T07-T10 create SQLAlchemy models for User, ApiKey, UsageStats, ApiToken
- Add User model with email unique constraint and relationships
- Add ApiKey model with encrypted key storage and user relationship
- Add UsageStats model with unique constraint (api_key_id, date, model)
- Add ApiToken model with token_hash indexing
- Configure all cascade delete relationships
- Add 49 comprehensive tests with 95% coverage

Models:
- User: id, email, password_hash, created_at, updated_at, is_active
- ApiKey: id, user_id, name, key_encrypted, is_active, created_at, last_used_at
- UsageStats: id, api_key_id, date, model, requests_count, tokens_input, tokens_output, cost
- ApiToken: id, user_id, token_hash, name, created_at, last_used_at, is_active

Tests: 49 passed, coverage 95%
2026-04-07 11:09:12 +02:00
Luca Sacchi Ricciardi
60d9228d91 feat(db): T06 create database connection and session management
- Add database.py with SQLAlchemy engine and session
- Implement get_db() for FastAPI dependency injection
- Implement init_db() for table creation
- Use SQLAlchemy 2.0 declarative_base() syntax
- Add comprehensive tests with 100% coverage

Tests: 11 passed, 100% coverage
2026-04-07 10:53:13 +02:00