This commit is contained in:
2026-02-03 02:58:02 -06:00
parent 34e6ef14df
commit ddf98af78a
2 changed files with 130 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
#!/bin/bash
# ============================================================================
# Database Migration Script
# Run a specific SQL migration file against the database
# ============================================================================
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Load environment variables
if [ -f ../.env ]; then
export $(cat ../.env | grep -v '^#' | xargs)
else
echo -e "${RED}Error: .env file not found${NC}"
exit 1
fi
# Check if migration file is provided
if [ -z "$1" ]; then
echo -e "${YELLOW}Usage: ./run-migration.sh <migration-file.sql>${NC}"
echo ""
echo "Available migrations:"
ls -1 ../sql/*.sql | grep -v schema.sql
exit 1
fi
MIGRATION_FILE=$1
# Check if file exists
if [ ! -f "../sql/$MIGRATION_FILE" ]; then
echo -e "${RED}Error: Migration file not found: ../sql/$MIGRATION_FILE${NC}"
exit 1
fi
# Construct database URL
DB_URL="postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}"
echo -e "${YELLOW}========================================${NC}"
echo -e "${YELLOW}Running migration: $MIGRATION_FILE${NC}"
echo -e "${YELLOW}Database: $DB_NAME${NC}"
echo -e "${YELLOW}========================================${NC}"
echo ""
# Run the migration
psql "$DB_URL" -f "../sql/$MIGRATION_FILE"
if [ $? -eq 0 ]; then
echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}✓ Migration completed successfully!${NC}"
echo -e "${GREEN}========================================${NC}"
else
echo ""
echo -e "${RED}========================================${NC}"
echo -e "${RED}✗ Migration failed!${NC}"
echo -e "${RED}========================================${NC}"
exit 1
fi