Files
you-music/backend/migrate.sh
T
2025-10-30 22:35:02 +11:00

80 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
# Database migration helper script
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Activate virtual environment
source .venv/bin/activate
case "$1" in
"init")
echo "🔧 Initializing Alembic (already done)..."
;;
"create")
if [ -z "$2" ]; then
echo "❌ Please provide a migration message"
echo "Usage: ./migrate.sh create \"migration message\""
exit 1
fi
echo "📝 Creating new migration: $2"
alembic revision --autogenerate -m "$2"
;;
"upgrade")
echo "⬆️ Upgrading database to latest version..."
alembic upgrade head
;;
"downgrade")
if [ -z "$2" ]; then
echo "⬇️ Downgrading database by 1 step..."
alembic downgrade -1
else
echo "⬇️ Downgrading database to: $2"
alembic downgrade "$2"
fi
;;
"history")
echo "📜 Migration history:"
alembic history
;;
"current")
echo "📍 Current database version:"
alembic current
;;
"stamp")
if [ -z "$2" ]; then
echo "🏷️ Stamping database to head..."
alembic stamp head
else
echo "🏷️ Stamping database to: $2"
alembic stamp "$2"
fi
;;
*)
echo "YouMusic Database Migration Tool"
echo ""
echo "Usage: ./migrate.sh <command> [options]"
echo ""
echo "Commands:"
echo " create <message> Create a new migration with autogenerate"
echo " upgrade [revision] Upgrade to latest (head) or specified revision"
echo " downgrade [revision] Downgrade one step or to specified revision"
echo " history Show migration history"
echo " current Show current database version"
echo " stamp [revision] Stamp database to head or specified revision (without running migrations)"
echo ""
echo "Examples:"
echo " ./migrate.sh create \"Add artist bio field\""
echo " ./migrate.sh upgrade"
echo " ./migrate.sh downgrade"
echo " ./migrate.sh history"
echo " ./migrate.sh current"
echo " ./migrate.sh stamp head"
exit 1
;;
esac
echo "✅ Done!"