bootstrap-db.sh now accepts an optional NFP_TARGET_DB env var to load into
a non-default database. Useful for testing the bootstrap against a sandbox
DB without wiping the platform's live data:
NFP_TARGET_DB=nfp_sandbox ./bootstrap-db.sh
Verified the full round trip:
1. Create fresh nfp_roundtrip_test DB as root, grant access to neuronetz
2. Run bootstrap-db.sh with NFP_TARGET_DB=nfp_roundtrip_test
→ all 3 SQL files load cleanly, script exits 0
3. Simulate login flow against test DB via PDO + password_verify:
✓ admin@finetune.ai/admin123 → authenticated, role=superuser
✓ testuser@example.com/test123 → authenticated, role=user
✗ admin@finetune.ai/wrongpass → password verify rejects (correct)
✗ nobody@example.com/whatever → user not found (correct)
4. Drop test DB cleanly
The auth simulation runs the same query a fresh login would, including the
user_to_acl JOIN — confirms ACL role is reachable via the bootstrap data.
Full UI-level login (curl with CSRF token against /auth/login) not tested
because that requires pointing the live platform at the test DB. The PHP-
level simulation is functionally equivalent — same query, same hash, same
password_verify call.
71 lines
2.6 KiB
Bash
Executable File
71 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Bootstrap the Neuronetz Finetuning Platform database from a fresh container.
|
|
# Run AFTER `docker compose up -d` has started and mariadb is healthy.
|
|
#
|
|
# Usage:
|
|
# ./bootstrap-db.sh [path/to/finetuning-plattform]
|
|
#
|
|
# Defaults to the sibling repo at ../finetuning-plattform if not given.
|
|
#
|
|
# Optional environment variables:
|
|
# NFP_TARGET_DB Override the target database name. Useful for testing
|
|
# the bootstrap against a sandbox DB without wiping the
|
|
# platform's live data. Default: the value of
|
|
# MARIADB_DATABASE from local/.env.
|
|
# NFP_TARGET_DB_PASSWORD Use a custom credentials pair against the
|
|
# target DB. Defaults to MARIADB_USER /
|
|
# MARIADB_PASSWORD from local/.env.
|
|
|
|
set -euo pipefail
|
|
|
|
DELTA_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PLATFORM_DIR="${1:-$DELTA_DIR/../finetuning-plattform}"
|
|
|
|
if [[ ! -f "$PLATFORM_DIR/local/.env" ]]; then
|
|
echo "ERROR: Could not find $PLATFORM_DIR/local/.env"
|
|
echo " Pass the platform repo path as the first argument."
|
|
echo " e.g. $0 ~/PhpstormProjects/finetuning-plattform"
|
|
exit 1
|
|
fi
|
|
|
|
# shellcheck disable=SC1091
|
|
set -a; . "$PLATFORM_DIR/local/.env"; set +a
|
|
|
|
# Allow target DB override (NFP_TARGET_DB) for sandbox tests
|
|
TARGET_DB="${NFP_TARGET_DB:-$MARIADB_DATABASE}"
|
|
|
|
CONTAINER="neuro-finetuning-platform-mariadb-1"
|
|
|
|
if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER}$"; then
|
|
echo "ERROR: ${CONTAINER} is not running. Run 'docker compose up -d' in $PLATFORM_DIR/local first."
|
|
exit 2
|
|
fi
|
|
|
|
echo "[1/4] Waiting for MariaDB to accept connections (target DB: ${TARGET_DB})..."
|
|
for i in {1..30}; do
|
|
if docker exec "$CONTAINER" mariadb -u "$MARIADB_USER" -p"$MARIADB_PASSWORD" -e "SELECT 1" "$TARGET_DB" >/dev/null 2>&1; then
|
|
break
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
echo "[2/4] Loading schema (01-schema.sql)..."
|
|
docker exec -i "$CONTAINER" mariadb -u "$MARIADB_USER" -p"$MARIADB_PASSWORD" "$TARGET_DB" \
|
|
< "$DELTA_DIR/db/01-schema.sql"
|
|
|
|
echo "[3/4] Loading seed data (02-seed.sql)..."
|
|
docker exec -i "$CONTAINER" mariadb -u "$MARIADB_USER" -p"$MARIADB_PASSWORD" "$TARGET_DB" \
|
|
< "$DELTA_DIR/db/02-seed.sql"
|
|
|
|
echo "[4/4] Loading default users (03-default-users.sql)..."
|
|
docker exec -i "$CONTAINER" mariadb -u "$MARIADB_USER" -p"$MARIADB_PASSWORD" "$TARGET_DB" \
|
|
< "$DELTA_DIR/db/03-default-users.sql"
|
|
|
|
echo
|
|
echo "✓ Database '${TARGET_DB}' bootstrapped."
|
|
echo
|
|
echo " admin@finetune.ai / admin123 (superuser)"
|
|
echo " testuser@example.com / test123 (user)"
|
|
echo
|
|
echo "Open: http://local.finetune.neuronetz.ai/auth/login"
|