Tests and Migrations¶
Databasez is designed for production services and test isolation flows.
Test isolation¶
For integration tests, use DatabaseTestClient.
Two common strategies:
- one reusable test database with rollback per test
- create/drop test database around suite runs
Databasez supports both with force_rollback, drop_database, and use_existing.
Migrations¶
Databasez works with SQLAlchemy Core metadata, so Alembic integration is straightforward.
In alembic.ini, remove:
In migrations/env.py, set URL and metadata:
from alembic import context
from myapp.settings import DATABASE_URL
from myapp.tables import metadata
config = context.config
config.set_main_option("sqlalchemy.url", str(DATABASE_URL))
target_metadata = metadata
Sync driver note¶
Alembic migrations run with synchronous SQLAlchemy engines/drivers. This is normal and separate from your async runtime queries.
Examples¶
Edgy is a good real-world example from the same ecosystem.