When using AI assistants (GitHub Copilot, ChatGPT, etc.) to work on this codebase, always provide these instructions:
NEVER add Base.metadata.create_all() to app/core/db.py
- Tables are managed exclusively through Alembic migrations
- The
init_db()function should ONLY import models, not create tables - This ensures schema changes are tracked, versioned, and reversible
Correct pattern:
def init_db() -> None:
"""Import all models to register them with SQLAlchemy."""
import app.models.document
import app.models.camera
import app.models.project
import app.models.user
# NO create_all() here!When adding/modifying models:
- Update the model in
app/models/ - Generate migration:
docker compose exec backend alembic revision --autogenerate -m "description" - Review the generated migration file
- Apply:
docker compose exec backend alembic upgrade head
- Custom token system is intentional - This is a standalone/offline Raspberry Pi application
- Do NOT suggest replacing with JWT libraries (python-jose, PyJWT) or OAuth2
- Do NOT add
pydantic[email]dependency - uses simple regex validation for offline compatibility - Secret keys must come from environment variables, never hardcoded
- Use
postgresql+psycopg://for psycopg3 (NOTpostgresql://) - Always test with PostgreSQL in development (matching production)
- Database URL format:
postgresql+psycopg://user:password@host:port/database
Only add settings that are used by application code
- Settings in
app/core/config.pyshould be consumed by the application - Infrastructure settings (uvicorn host/port) belong in
docker-compose.yml, not Settings - If you're adding a field to Settings, ensure it's actually used in the code
- Use
docker compose(notdocker-compose) on Raspberry Pi - Always exec into container for Alembic:
docker compose exec backend alembic ...
- ✗ Re-adding
create_all()after it was intentionally removed - ✗ Suggesting JWT/OAuth2 for a standalone offline application
- ✗ Adding unused configuration fields "just in case"
- ✗ Using
postgresql://instead ofpostgresql+psycopg:// - ✗ Creating migrations outside Docker (wrong database host)
docker compose exec backend alembic upgrade headdocker compose exec backend alembic revision --autogenerate -m "description"docker compose exec backend python -c "from app.core.db import engine; from sqlalchemy import inspect; print(inspect(engine).get_table_names())"docker compose exec backend python test_api.pyProject Type: Digitization toolkit for standalone Raspberry Pi deployment
Environment: Offline-capable, single-instance
Database: PostgreSQL with psycopg3
Migrations: Alembic (strict - no auto table creation)
Auth: Custom HMAC tokens (no JWT libraries)
When in doubt, check git history before making changes that might revert previous intentional decisions.