Skip to main content

What is it

Alembic is a lightweight database migration tool that manages database schema changes over time. Think of it as “version control for your database” - it tracks changes and lets you upgrade or rollback your database structure safely.

Why we use it

The Launchpad uses Alembic because it integrates seamlessly with our SQLAlchemy models, automatically detects schema changes, and ensures all environments stay synchronized.

Where we use it

We use Alembic for all database schema changes in the project. Here’s how it works: Basic Commands:
  • Create Migration: ./makemigration.sh
  • Apply Migration: ./migrate.sh
Complete Workflow:
  1. Modify your SQLAlchemy model (e.g., in database/event.py)
  2. Generate migration: ./makemigration.sh → Enter migration message
  3. Review the generated migration in alembic/versions/
  4. Apply the migration: ./migrate.sh
For Alembic to detect your models, you must import them in alembic/env.py
# alembic/env.py
from database.session import Base
from database.event import *     # Import Event model
from database.user import *      # Import User model  
from database.workflow import *  # Import all other models
Project Structure:
app/
├── alembic.ini            # Alembic configuration
├── alembic/
│   ├── env.py             # Environment setup (import models here!)
│   └── versions/          # Generated migration files
├── makemigration.sh       # Create migrations
└── migrate.sh             # Apply migrations
Development Commands:
  • Apply migrations: ./migrate.sh
  • Check current version: alembic current
  • View history: alembic history
  • Rollback: alembic downgrade -1
Always review generated migrations before applying - autogenerate is smart but not perfect!

Further Reading

For advanced Alembic features and detailed configuration options, refer to the official Alembic documentation.
I