#!/bin/bash
# Run all SQL migrations in order
set -e

DB_URL="${DATABASE_URL:-postgresql://genex:genex_dev@localhost:5432/genex}"

echo "Running migrations against: $DB_URL"

for f in $(ls -1 migrations/*.sql | sort); do
  echo "Applying: $f"
  psql "$DB_URL" -f "$f"
done

echo "All migrations applied."

# Optionally load seed data
if [[ "$1" == "--seed" ]]; then
  echo "Loading seed data..."
  psql "$DB_URL" -f migrations/seed_data.sql
  echo "Seed data loaded."
fi
