Files
truenas-stacks/home/doris-schoolhouse/bin/apply-postgres-schema.sh

25 lines
600 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/.."
SCHEMA_FILE="app/db/schema.sql"
if [ ! -f "$SCHEMA_FILE" ]; then
echo "schema file missing: $SCHEMA_FILE" >&2
exit 1
fi
if [ -n "${DATABASE_URL:-}" ] && command -v python3 >/dev/null 2>&1; then
export PYTHONPATH=.
python3 app/scripts/apply_schema.py
exit $?
fi
cat >&2 <<'MSG'
Cannot apply schema automatically.
Requirements:
- DATABASE_URL must be set
- python3 must be available
- psycopg must be installed for direct apply
Alternative: run the SQL in app/db/schema.sql manually against the schoolhouse database.
MSG
exit 1