#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" CANONICAL_SCHEMA="$ROOT_DIR/frontend/prisma/schema.prisma" TARGETS=( "$ROOT_DIR/omni_chat/prisma/schema.prisma" "$ROOT_DIR/omni_outbound/prisma/schema.prisma" ) if [[ ! -f "$CANONICAL_SCHEMA" ]]; then echo "[prisma-check] Canonical schema not found: $CANONICAL_SCHEMA" >&2 exit 1 fi status=0 for target in "${TARGETS[@]}"; do if [[ ! -f "$target" ]]; then echo "[prisma-check] Missing schema: $target" >&2 status=1 continue fi if ! cmp -s "$CANONICAL_SCHEMA" "$target"; then echo "[prisma-check] Schema drift detected: $target" >&2 status=1 else echo "[prisma-check] OK: $target" fi done # Enforce one rollout point for schema changes: # only frontend is allowed to run db push/migration commands. if rg -n "prisma (db push|migrate|migrate deploy|migrate dev)" \ "$ROOT_DIR/omni_chat" "$ROOT_DIR/omni_outbound" \ --glob '!**/node_modules/**' \ --glob '!**/package-lock.json' \ --glob '!**/README.md' > /tmp/prisma_non_frontend_migrations.txt; then echo "[prisma-check] Forbidden Prisma migration/db push command outside frontend:" >&2 cat /tmp/prisma_non_frontend_migrations.txt >&2 status=1 else echo "[prisma-check] OK: no migration/db push commands in omni services" fi if [[ "$status" -ne 0 ]]; then echo "[prisma-check] Failed. Run scripts/prisma-sync.sh and commit schema updates." >&2 exit "$status" fi echo "[prisma-check] Passed."