> ## Documentation Index
> Fetch the complete documentation index at: https://launchpad.datalumina.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Database Migrations

> Manage database schema changes systematically with Alembic migrations

## 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`

<Warning>
  For Alembic to detect your models, you must import them in `alembic/env.py`
</Warning>

```python theme={null}
# alembic/env.py
from launchpad.database.session import Base
from launchpad.database.event import *  # Import Event model for autogenerate

# Import additional SQLAlchemy models here when you add them.
```

**Project Structure:**

```
app/launchpad/
├── 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](https://alembic.sqlalchemy.org/).
