Files
simbarag/services/raggr/MIGRATIONS.md
Ryan Chen 70799ffb7d refactor
2025-11-10 15:51:13 -05:00

1.1 KiB

Database Migrations with Aerich

Initial Setup (Run Once)

  1. Install dependencies:
uv pip install -e .
  1. Initialize Aerich:
aerich init-db

This will:

  • Create a migrations/ directory
  • Generate the initial migration based on your models
  • Create all tables in the database

When You Add/Change Models

  1. Generate a new migration:
aerich migrate --name "describe_your_changes"

Example:

aerich migrate --name "add_user_profile_model"
  1. Apply the migration:
aerich upgrade

Common Commands

  • aerich init-db - Initialize database (first time only)
  • aerich migrate --name "description" - Generate new migration
  • aerich upgrade - Apply pending migrations
  • aerich downgrade - Rollback last migration
  • aerich history - Show migration history
  • aerich heads - Show current migration heads

Docker Setup

In Docker, migrations run automatically on container startup via the startup script.

Notes

  • Migration files are stored in migrations/models/
  • Always commit migration files to version control
  • Don't modify migration files manually after they're created