#!/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"