| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 5 个月前 | ||
| 7 个月前 | ||
| 7 个月前 | ||
| 6 个月前 | ||
| 7 个月前 |
Alembic Database Migration
Generic single-database configuration.
Automatic Migration
When the server starts, it will automatically:
- Check if tables exist without
alembic_version→ stamp to current version - Run
alembic upgrade headto apply any pending migrations - Use Redis lock to ensure only one instance runs migrations at a time
Manual Migration Commands
Create a new migration
# Auto-generate migration from model changes
alembic revision --autogenerate -m "description of changes"
# Create empty migration file
alembic revision -m "description of changes"
Rollback migrations
⚠️ Important Notes:
- Downgrade database first - Run the downgrade command in the new version code (which contains the downgrade migration)
- Then downgrade service - After database downgrade is complete, downgrade the workflow service to the compatible version and restart it
- Data loss risk - Downgrading may cause data loss if the migration removes columns or tables. Always backup your database first
# Downgrade one step
alembic downgrade -1
# Downgrade to specific version
alembic downgrade <revision>
# Downgrade all migrations
alembic downgrade base
Workflow for Model Changes
-
Modify your SQLModel classes in
workflow/domain/models/ -
Generate migration:
alembic revision --autogenerate -m "add user table" -
Review the generated file in
alembic/versions/ -
Edit if needed - autogenerate may not catch everything:
- Data migrations
- Index renames
- Complex constraint changes
-
Commit the migration file to git