#!/bin/bash
set -e

# Script for applying migrations in the lab environment
# Usage: ./scripts/apply_migrations_lab.sh

# Définir les variables de couleurs
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

echo -e "${GREEN}🔧 Setup migration environment...${NC}"

# Priorité : VEZA_LAB_DSN > DATABASE_URL default
if [ -n "$VEZA_LAB_DSN" ]; then
    export DATABASE_URL="$VEZA_LAB_DSN"
    echo -e "Using VEZA_LAB_DSN: $DATABASE_URL"
elif [ -z "$DATABASE_URL" ]; then
    # Default lab DSN if nothing set
    export DATABASE_URL="postgres://veza:veza_password@localhost:5432/veza_lab?sslmode=disable"
    echo -e "${YELLOW}Warning: No DATABASE_URL set. Using default Lab DSN: $DATABASE_URL${NC}"
fi

echo -e "${GREEN}📦 Running migrations...${NC}"
go run cmd/migrate_tool/main.go

echo -e "${GREEN}✅ Migrations applied successfully!${NC}"
