#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$ROOT_DIR" if [[ -f ".env.local" ]]; then # shellcheck disable=SC1091 source ".env.local" fi if [[ -f ".env" ]]; then # shellcheck disable=SC1091 source ".env" fi if [[ -z "${DATABASE_URL:-}" ]]; then echo "DATABASE_URL 未设置" >&2 exit 1 fi find "db/migrations" -maxdepth 1 -type f -name "*.sql" | sort | while read -r migration; do psql "$DATABASE_URL" -v ON_ERROR_STOP=1 -f "$migration" echo "migration 已应用: $migration" done