#!/bin/sh
set -eu

STATE_DIR="/state"
MARKER_FILE="$STATE_DIR/dev-bootstrap-complete"

mkdir -p "$STATE_DIR"

echo "[migrate] Generating database client"
npm run db:generate

if [ -f "$MARKER_FILE" ]; then
  echo "[migrate] Existing dev database detected; skipping deploy and seed"
  exit 0
fi

echo "[migrate] First dev bootstrap; applying schema and seed data"
npm run db:deploy
npm run db:seed

touch "$MARKER_FILE"
echo "[migrate] Dev bootstrap complete"
