Agent skill

migrate-baselhussain-ai-keto-meal-plan-ge

Database migration management (create, apply, rollback using Alembic)

Stars 163
Forks 31

Install this agent skill to your Project

npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/migrate-baselhussain-ai-keto-meal-plan-ge

SKILL.md

User Input

text
$ARGUMENTS

Commands: up (apply), down (rollback), create <message>, status, history

Task

Manage database migrations using Alembic for the keto meal plan project.

Steps

  1. Parse Arguments:

    • up or empty: Apply all pending migrations
    • down or down <N>: Rollback N migrations (default: 1)
    • create <message>: Create new migration from model changes
    • status: Show current migration status
    • history: Show migration history
  2. Navigate to Backend Directory:

    bash
    cd backend
    
  3. Execute Command:

    For up (Apply Migrations):

    bash
    # Show pending migrations first
    alembic current
    alembic heads
    
    # Apply migrations
    alembic upgrade head
    
    # Verify success
    alembic current
    

    For down (Rollback):

    bash
    # Show current version
    alembic current
    
    # Rollback (default: 1 step)
    alembic downgrade -1
    
    # Or rollback N steps if specified
    # alembic downgrade -N
    
    # Verify rollback
    alembic current
    

    For create <message> (Create Migration):

    bash
    # Generate migration from SQLAlchemy model changes
    alembic revision --autogenerate -m "<message>"
    
    # Show generated migration file path
    # Example: database/migrations/versions/abc123_add_column.py
    

    For status (Show Status):

    bash
    # Current version
    alembic current
    
    # Latest available version
    alembic heads
    
    # Check for pending migrations
    alembic upgrade head --sql | head -20
    

    For history (Show History):

    bash
    # Show all migrations
    alembic history --verbose
    
  4. Validate Database Connection:

    bash
    # Test database connection
    python -c "from src.lib.database import engine; print('✅ Database connection successful')"
    
  5. Output Summary:

    ✅ Migration Summary
    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    Command: [up/down/create/status/history]
    
    Current Version: abc123_migration_name
    [Status information based on command]
    
    Database: [connection string without password]
    
  6. Recommendations:

    • After create: "Review migration file at database/migrations/versions/XXX.py before applying"
    • After up: "Migration applied successfully. Verify database schema."
    • After down: "⚠️ Migration rolled back. Data may be lost. Verify database state."

Example Usage

bash
/migrate                          # Apply all pending migrations
/migrate up                       # Apply all pending migrations
/migrate down                     # Rollback last migration
/migrate down 2                   # Rollback 2 migrations
/migrate create "Add user preferences"  # Create new migration
/migrate status                   # Show migration status
/migrate history                  # Show migration history

Exit Criteria

  • Migration command executes successfully
  • Database connection verified
  • Current migration version displayed
  • Migration files reviewed (for create command)

Safety Notes

  • Always backup production database before running migrations
  • Review autogenerated migrations - Alembic may not detect all changes
  • Test migrations on development database first
  • Rollback carefully - downgrade may cause data loss

Expand your agent's capabilities with these related and highly-rated skills.

Didn't find tool you were looking for?

Be as detailed as possible for better results