#!/bin/bash

set -euo pipefail

if ! command -v node >/dev/null 2>&1; then
  echo "node is required."
  exit 1
fi

if [ -z "${DATABASE_URL:-}" ]; then
  echo "DATABASE_URL is required. Aborting."
  exit 1
fi

echo "Checking migration status..."
npm run db:migrate:status

echo "Applying pending migrations..."
npm run db:migrate

echo "Final migration status..."
npm run db:migrate:status

echo "Done."
