diff options
Diffstat (limited to 'backend')
| -rwxr-xr-x | backend/database/dev/backup/apply-updates.sh | 121 | ||||
| -rw-r--r-- | backend/database/dev/backup/beepzone-schema-consolidated-backup.sql (renamed from backend/database/dev/beepzone-schema-consolidated-backup.sql) | 0 | ||||
| -rw-r--r-- | backend/database/dev/backup/beepzone-schema-dump.sql (renamed from backend/database/dev/beepzone-schema-dump.sql) | 0 | ||||
| -rwxr-xr-x | backend/database/dev/backup/export-clean-schema.sh (renamed from backend/database/dev/export-clean-schema.sh) | 0 | ||||
| -rwxr-xr-x | backend/database/dev/backup/run-client.sh | 24 | ||||
| -rwxr-xr-x | backend/database/dev/backup/run-seckelapi.sh | 24 | ||||
| -rw-r--r-- | backend/database/dev/backup/update_001_add_tag_generation_string.sql (renamed from backend/database/dev/update_001_add_tag_generation_string.sql) | 0 | ||||
| -rw-r--r-- | backend/database/dev/backup/update_002_add_asset_relationships.sql (renamed from backend/database/dev/update_002_add_asset_relationships.sql) | 0 | ||||
| -rw-r--r-- | backend/database/dev/backup/update_003_make_zone_code_required_unique.sql (renamed from backend/database/dev/update_003_make_zone_code_required_unique.sql) | 0 |
9 files changed, 169 insertions, 0 deletions
diff --git a/backend/database/dev/backup/apply-updates.sh b/backend/database/dev/backup/apply-updates.sh new file mode 100755 index 0000000..3d89c43 --- /dev/null +++ b/backend/database/dev/backup/apply-updates.sh @@ -0,0 +1,121 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# BeepZone Slop Database Updater +# Applies SQL update scripts from backend/database/dev/ to the configured database. + +if ! command -v "$DIALOG" >/dev/null 2>&1; then + echo "\n[ERROR] 'dialog' is not installed or not in PATH." >&2 + echo "On macOS: brew install dialog" >&2 + echo "On Debian: sudo apt install dialog" >&2 + exit 1 +fi + +dialog --title "BeepZone" --yes-label "Exit" --no-label "Ignore" --yesno "Drop this in the root of the beepzone setup git directory before running" 10 60 + if [ $? -eq 0 ]; then + exit 1 + fi + + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +WORK_DIR="${SCRIPT_DIR}" + +# Check for MariaDB/MySQL client - try common brew locations on macOS +MYSQL_CLIENT="" +if command -v mariadb >/dev/null 2>&1; then + MYSQL_CLIENT="mariadb" +elif command -v mysql >/dev/null 2>&1; then + MYSQL_CLIENT="mysql" +elif [[ -x /opt/homebrew/opt/mysql-client/bin/mysql ]]; then + MYSQL_CLIENT="/opt/homebrew/opt/mysql-client/bin/mysql" + export PATH="/opt/homebrew/opt/mysql-client/bin:$PATH" +elif [[ -x /opt/homebrew/opt/mariadb/bin/mariadb ]]; then + MYSQL_CLIENT="/opt/homebrew/opt/mariadb/bin/mariadb" + export PATH="/opt/homebrew/opt/mariadb/bin:$PATH" +elif [[ -x /opt/homebrew/bin/mariadb ]]; then + MYSQL_CLIENT="/opt/homebrew/bin/mariadb" + export PATH="/opt/homebrew/bin:$PATH" +elif [[ -x /opt/homebrew/bin/mysql ]]; then + MYSQL_CLIENT="/opt/homebrew/bin/mysql" + export PATH="/opt/homebrew/bin:$PATH" +elif [[ -x /usr/local/opt/mysql-client/bin/mysql ]]; then + MYSQL_CLIENT="/usr/local/opt/mysql-client/bin/mysql" + export PATH="/usr/local/opt/mysql-client/bin:$PATH" +elif [[ -x /usr/local/bin/mariadb ]]; then + MYSQL_CLIENT="/usr/local/bin/mariadb" + export PATH="/usr/local/bin:$PATH" +elif [[ -x /usr/local/bin/mysql ]]; then + MYSQL_CLIENT="/usr/local/bin/mysql" + export PATH="/usr/local/bin:$PATH" +else + echo "[ERROR] MariaDB/MySQL client is required but not found." + exit 1 +fi + +ENV_FILE="$SCRIPT_DIR/.env" + +# Load existing settings from .env if present +if [[ -f "$ENV_FILE" ]]; then + source "$ENV_FILE" +else + echo "[ERROR] .env file not found. Please run beepzone-helper.sh first to configure the environment." + exit 1 +fi + +# Set defaults if not loaded from .env (though they should be) +: "${DB_HOST:=127.0.0.1}" +: "${DB_PORT:=3306}" +: "${DB_NAME:=beepzone}" +: "${DB_USER:=beepzone}" +: "${DB_PASS:=beepzone}" + +echo "=== BeepZone Database Updater ===" +echo "Target Database: $DB_NAME on $DB_HOST:$DB_PORT" +echo "User: $DB_USER" +echo "" + +UPDATES_DIR="$WORK_DIR/backend/database/dev" + +if [[ ! -d "$UPDATES_DIR" ]]; then + echo "[ERROR] Updates directory not found: $UPDATES_DIR" + exit 1 +fi + +# Find update scripts +update_scripts=($(find "$UPDATES_DIR" -name "update_003*.sql" | sort)) + +if [[ ${#update_scripts[@]} -eq 0 ]]; then + echo "No update scripts found in $UPDATES_DIR." + exit 0 +fi + +echo "Found ${#update_scripts[@]} update script(s):" +for script in "${update_scripts[@]}"; do + echo " - $(basename "$script")" +done +echo "" + +read -p "Do you want to apply these updates? (y/N) " -n 1 -r +echo "" +if [[ ! $REPLY =~ ^[Yy]$ ]]; then + echo "Aborted." + exit 0 +fi + +echo "" +for script in "${update_scripts[@]}"; do + script_name=$(basename "$script") + echo "Applying $script_name..." + + if "$MYSQL_CLIENT" -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USER" -p"$DB_PASS" "$DB_NAME" < "$script"; then + echo " [OK] $script_name applied successfully." + else + echo " [ERROR] Failed to apply $script_name." + echo "Stopping further updates." + exit 1 + fi +done + +echo "" +echo "All updates applied successfully." diff --git a/backend/database/dev/beepzone-schema-consolidated-backup.sql b/backend/database/dev/backup/beepzone-schema-consolidated-backup.sql index e91043c..e91043c 100644 --- a/backend/database/dev/beepzone-schema-consolidated-backup.sql +++ b/backend/database/dev/backup/beepzone-schema-consolidated-backup.sql diff --git a/backend/database/dev/beepzone-schema-dump.sql b/backend/database/dev/backup/beepzone-schema-dump.sql index 3acb5e5..3acb5e5 100644 --- a/backend/database/dev/beepzone-schema-dump.sql +++ b/backend/database/dev/backup/beepzone-schema-dump.sql diff --git a/backend/database/dev/export-clean-schema.sh b/backend/database/dev/backup/export-clean-schema.sh index 3548183..3548183 100755 --- a/backend/database/dev/export-clean-schema.sh +++ b/backend/database/dev/backup/export-clean-schema.sh diff --git a/backend/database/dev/backup/run-client.sh b/backend/database/dev/backup/run-client.sh new file mode 100755 index 0000000..49ff3e8 --- /dev/null +++ b/backend/database/dev/backup/run-client.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +CLIENT_BIN="$SCRIPT_DIR/frontend/desktop-client/sources/target/release/beepzone-egui" +CLIENT_SOURCES="$SCRIPT_DIR/frontend/desktop-client/sources" + +if [[ ! -f "$CLIENT_BIN" ]]; then + echo "Error: BeepZone client binary not found at:" + echo " $CLIENT_BIN" + echo "" + echo "Please build the desktop client first using the setup helper:" + echo " ./beepzone-helper.sh" + exit 1 +fi + +echo "Starting BeepZone Desktop Client..." +echo "Binary: $CLIENT_BIN" +echo "Working directory: $CLIENT_SOURCES" +echo "" + +cd "$CLIENT_SOURCES" +exec ./target/release/beepzone-egui diff --git a/backend/database/dev/backup/run-seckelapi.sh b/backend/database/dev/backup/run-seckelapi.sh new file mode 100755 index 0000000..85cd7d5 --- /dev/null +++ b/backend/database/dev/backup/run-seckelapi.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SECKELAPI_BIN="$SCRIPT_DIR/backend/seckelapi/sources/target/release/seckelapi" +SECKELAPI_SOURCES="$SCRIPT_DIR/backend/seckelapi/sources" + +if [[ ! -f "$SECKELAPI_BIN" ]]; then + echo "Error: SeckelAPI binary not found at:" + echo " $SECKELAPI_BIN" + echo "" + echo "Please build SeckelAPI first using the setup helper:" + echo " ./beepzone-helper.sh" + exit 1 +fi + +echo "Starting SeckelAPI..." +echo "Binary: $SECKELAPI_BIN" +echo "Working directory: $SECKELAPI_SOURCES" +echo "" + +cd "$SECKELAPI_SOURCES" +exec ./target/release/seckelapi diff --git a/backend/database/dev/update_001_add_tag_generation_string.sql b/backend/database/dev/backup/update_001_add_tag_generation_string.sql index 61308fd..61308fd 100644 --- a/backend/database/dev/update_001_add_tag_generation_string.sql +++ b/backend/database/dev/backup/update_001_add_tag_generation_string.sql diff --git a/backend/database/dev/update_002_add_asset_relationships.sql b/backend/database/dev/backup/update_002_add_asset_relationships.sql index 0d74b89..0d74b89 100644 --- a/backend/database/dev/update_002_add_asset_relationships.sql +++ b/backend/database/dev/backup/update_002_add_asset_relationships.sql diff --git a/backend/database/dev/update_003_make_zone_code_required_unique.sql b/backend/database/dev/backup/update_003_make_zone_code_required_unique.sql index 08e8896..08e8896 100644 --- a/backend/database/dev/update_003_make_zone_code_required_unique.sql +++ b/backend/database/dev/backup/update_003_make_zone_code_required_unique.sql |
