#!/bin/bash # Applies database migrations in order. # Usage: ./migrate.sh [up|down] set -euo pipefail DB_URL="${DATABASE_URL:-postgresql://brain:brain@localhost:5432/second_brain}" MIGRATIONS_DIR="$(dirname "$0")/migrations" ACTION="${1:-up}" if [ "$ACTION" = "up" ]; then echo "Applying schema..." psql "$DB_URL" -f "$(dirname "$0")/schema.sql" echo "Schema applied." elif [ "$ACTION" = "down" ]; then echo "Dropping schema..." psql "$DB_URL" -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;" echo "Schema dropped." fi