#!/bin/bash

# Postinstall script that safely runs prisma generate
# Skips generation only when no DATABASE_URL can be resolved at all (e.g., in CI without DB).
# prisma.config.ts loads .env then .env.local, so a local dev with a .env.local does not
# need DATABASE_URL exported in the shell for `prisma generate` to succeed.

if [ -z "$DATABASE_URL" ] && [ ! -f .env ] && [ ! -f .env.local ]; then
  echo "⚠️  No DATABASE_URL and no .env/.env.local, skipping prisma generate (will run explicitly in workflow)"
  exit 0
fi

npx prisma generate
