#!/bin/sh

set -eu

for migration in /migrations/*.sql; do
  case "$migration" in
    */006_rls_and_grants.sql)
      echo "Skipping $migration because it contains deployment-specific grants."
      ;;
    *)
      echo "Applying $migration"
      psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -f "$migration"
      ;;
  esac
done
