ghost-sweep uses Alembic with async SQLAlchemy against PostgreSQL 15. Batch 2 introduces the initial UUID schema migration that matches the current ORM models.
- Python 3.11
- PostgreSQL 15
- Backend dev dependencies installed:
pip install "./backend[dev]" - A dedicated database for local development or testing
| Variable | Purpose |
|---|---|
DATABASE_URL |
Application database URL used by FastAPI and Alembic at runtime |
TEST_DATABASE_URL |
Integration test database URL used by pytest migration and DB fixtures |
Example test URL when using Docker Compose postgres_test on the host:
postgresql+asyncpg://ghost_sweep:ghost_sweep@localhost:5433/ghost_sweep_test
The main development database on port 5432 uses database name ghost_sweep, not ghost_sweep_test.
From the repository root:
cd backend
alembic upgrade headAlembic reads DATABASE_URL through app.config.get_settings().
Migration verification tests require TEST_DATABASE_URL:
cd backend
TEST_DATABASE_URL="postgresql+asyncpg://ghost_sweep:ghost_sweep@localhost:5432/ghost_sweep_test" \
pytest tests/test_migrations.py -vThese tests verify:
- Alembic records revision
001_initial_uuid_schema - Core entity tables exist
- Native PostgreSQL ENUM types exist
uq_votes_report_useris present onvotes- Downgrade to base and upgrade to head succeed
Unit tests that do not require PostgreSQL continue to run without TEST_DATABASE_URL.
- Primary keys use UUID columns
- Enumerated model fields use PostgreSQL native ENUM types
- JSONB stores list and breakdown payloads
- Foreign keys follow the current ORM relationship graph
votes.report_idandvotes.user_idare unique together
To remove the initial schema locally:
cd backend
alembic downgrade baseDowngrade drops all Batch 1 tables and removes the PostgreSQL ENUM types created by the initial migration.
- Docker entrypoint migration automation
- CI migration steps
- API routes and auth flows
- Frontend, extension, and deployment changes
Those items are planned for later batches after the database foundation is reviewed.