Database Migrations¶
fastapi-fullauth provides Alembic integration helpers for managing database schema migrations.
Quick start (without Alembic)¶
For development or simple projects, create tables directly:
Alembic integration¶
For production, use Alembic for proper migration management.
1. Initialize Alembic¶
2. Update env.py¶
Import fullauth models so Alembic detects them during autogenerate:
3. Generate migrations¶
Model groups¶
Models are split into groups. Import only what you need:
| Group | Tables | When to include |
|---|---|---|
base |
fullauth_users, fullauth_refresh_tokens |
Always (core auth) |
role |
fullauth_roles, fullauth_user_roles |
When using roles |
permission |
fullauth_permissions, fullauth_role_permissions |
When using RBAC permissions |
oauth |
fullauth_oauth_accounts |
When using OAuth providers |
Helper functions¶
include_fullauth_models(adapter, include=None)¶
Imports fullauth model classes so Alembic's autogenerate detects them. Call this in env.py before setting target_metadata.
from fastapi_fullauth.migrations import include_fullauth_models
# all tables
include_fullauth_models("sqlmodel")
# selective — only core + roles
include_fullauth_models("sqlmodel", include=["base", "role"])
get_fullauth_metadata(adapter)¶
Returns the SQLAlchemy MetaData object containing fullauth table definitions. Useful if you need to merge metadata from multiple sources.