#!/bin/bash
# Script helper pour gérer les migrations Alembic

set -e

case "$1" in
    create)
        if [ -z "$2" ]; then
            echo "Usage: ./scripts/migrate.sh create 'message de migration'"
            exit 1
        fi
        alembic revision --autogenerate -m "$2"
        ;;
    upgrade)
        alembic upgrade head
        ;;
    downgrade)
        if [ -z "$2" ]; then
            alembic downgrade -1
        else
            alembic downgrade "$2"
        fi
        ;;
    current)
        alembic current
        ;;
    history)
        alembic history
        ;;
    *)
        echo "Usage: ./scripts/migrate.sh {create|upgrade|downgrade|current|history}"
        echo ""
        echo "Commands:"
        echo "  create 'message'  - Créer une nouvelle migration"
        echo "  upgrade           - Appliquer toutes les migrations en attente"
        echo "  downgrade [rev]   - Revenir en arrière (par défaut -1)"
        echo "  current           - Afficher la migration actuelle"
        echo "  history           - Afficher l'historique des migrations"
        exit 1
        ;;
esac


