70 lines
1.9 KiB
Bash
70 lines
1.9 KiB
Bash
#!/bin/bash
|
|
# database/scripts/migrate.sh
|
|
|
|
set -e
|
|
|
|
# Colors
|
|
GREEN='\033[0;32m'
|
|
RED='\033[0;31m'
|
|
NC='\033[0m'
|
|
|
|
# Database connection
|
|
DB_HOST="${DB_HOST:-localhost}"
|
|
DB_PORT="${DB_PORT:-5432}"
|
|
DB_NAME="${DB_NAME:-aurganize_dev}"
|
|
DB_USER="${DB_USER:-postgres}"
|
|
DB_PASSWORD="${DB_PASSWORD:-dev_pass_aurganize@v6.2}"
|
|
|
|
DATABASE_URL="postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?sslmode=disable"
|
|
|
|
# Migration directory
|
|
MIGRATIONS_DIR="$(dirname "$0")/../migrations"
|
|
|
|
echo "==================================================================="
|
|
echo "Aurganize V6.2 - Database Migration"
|
|
echo "==================================================================="
|
|
echo "Database: ${DB_NAME}"
|
|
echo "Migrations: ${MIGRATIONS_DIR}"
|
|
echo ""
|
|
|
|
# Parse command
|
|
case "$1" in
|
|
up)
|
|
echo "⬆️ Applying all migrations..."
|
|
migrate -path "${MIGRATIONS_DIR}" -database "${DATABASE_URL}" up
|
|
echo -e "${GREEN}✓ Migrations applied successfully${NC}"
|
|
;;
|
|
|
|
down)
|
|
echo "⬇️ Rolling back one migration..."
|
|
migrate -path "${MIGRATIONS_DIR}" -database "${DATABASE_URL}" down 1
|
|
echo -e "${GREEN}✓ Migration rolled back${NC}"
|
|
;;
|
|
|
|
version)
|
|
echo "Current version:"
|
|
migrate -path "${MIGRATIONS_DIR}" -database "${DATABASE_URL}" version
|
|
;;
|
|
|
|
force)
|
|
if [ -z "$2" ]; then
|
|
echo -e "${RED}Error: Version number required${NC}"
|
|
echo "Usage: $0 force <version>"
|
|
exit 1
|
|
fi
|
|
echo "⚠️ Forcing version to $2..."
|
|
migrate -path "${MIGRATIONS_DIR}" -database "${DATABASE_URL}" force "$2"
|
|
echo -e "${GREEN}✓ Version forced${NC}"
|
|
;;
|
|
|
|
*)
|
|
echo "Usage: $0 {up|down|version|force <version>}"
|
|
echo ""
|
|
echo "Commands:"
|
|
echo " up Apply all pending migrations"
|
|
echo " down Rollback the last migration"
|
|
echo " version Show current migration version"
|
|
echo " force Force database to specific version (use with caution!)"
|
|
exit 1
|
|
;;
|
|
esac |