Преглед изворни кода

item replacement and relationships db update

UMTS at Teleco пре 1 месец
родитељ
комит
93317bd021

+ 108 - 0
apply-updates.sh

@@ -0,0 +1,108 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+# BeepZone Database Updater
+# Applies SQL update scripts from backend/database/dev/ to the configured database.
+
+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_*.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."

Разлика између датотеке није приказан због своје велике величине
+ 1 - 1
backend/database/dev/beepzone-full-dump.sql


+ 2 - 2
backend/database/dev/export-full-dump.sh

@@ -9,8 +9,8 @@ export PATH="/opt/homebrew/opt/mysql-client/bin:$PATH"
 
 DB_HOST="127.0.0.1"
 DB_PORT="3306"
-DB_USER="beepzone_user"
-DB_PASS="BeepZONE77"
+DB_USER="beepzone"
+DB_PASS="beepzone"
 DB_NAME="beepzone"
 
 echo "Exporting full database dump (schema + data + triggers)..."

+ 1 - 0
backend/database/dev/update_001_add_tag_generation_string.sql

@@ -0,0 +1 @@
+ALTER TABLE `assets` ADD COLUMN `tag_generation_string` VARCHAR(255) DEFAULT NULL AFTER `asset_tag`;

+ 11 - 0
backend/database/dev/update_002_add_asset_relationships.sql

@@ -0,0 +1,11 @@
+ALTER TABLE `assets` 
+ADD COLUMN `belongs_to_item` INT(11) DEFAULT NULL COMMENT 'References asset_numeric_id of parent asset' AFTER `asset_numeric_id`,
+ADD COLUMN `previously_was` INT(11) DEFAULT NULL COMMENT 'References asset_numeric_id of the asset this replaced' AFTER `belongs_to_item`;
+
+ALTER TABLE `assets`
+ADD KEY `idx_belongs_to` (`belongs_to_item`),
+ADD KEY `idx_previously_was` (`previously_was`);
+
+ALTER TABLE `assets`
+ADD CONSTRAINT `fk_assets_belongs_to` FOREIGN KEY (`belongs_to_item`) REFERENCES `assets` (`asset_numeric_id`) ON DELETE SET NULL,
+ADD CONSTRAINT `fk_assets_previously_was` FOREIGN KEY (`previously_was`) REFERENCES `assets` (`asset_numeric_id`) ON DELETE SET NULL;

+ 8 - 1
backend/database/schema/beepzone-schema-dump.sql

@@ -28,7 +28,10 @@ CREATE TABLE `asset_change_log` (
 CREATE TABLE `assets` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `asset_tag` varchar(200) DEFAULT NULL,
+  `tag_generation_string` varchar(255) DEFAULT NULL,
   `asset_numeric_id` int(11) NOT NULL CHECK (`asset_numeric_id` between 10000000 and 99999999),
+  `belongs_to_item` int(11) DEFAULT NULL COMMENT 'References asset_numeric_id of parent asset',
+  `previously_was` int(11) DEFAULT NULL COMMENT 'References asset_numeric_id of the asset this replaced',
   `asset_type` enum('N','B','L','C') NOT NULL,
   `name` varchar(255) DEFAULT NULL,
   `category_id` int(11) DEFAULT NULL,
@@ -76,6 +79,8 @@ CREATE TABLE `assets` (
   KEY `last_modified_by` (`last_modified_by`),
   KEY `idx_asset_tag` (`asset_tag`),
   KEY `idx_asset_numeric` (`asset_numeric_id`),
+  KEY `idx_belongs_to` (`belongs_to_item`),
+  KEY `idx_previously_was` (`previously_was`),
   KEY `idx_type` (`asset_type`),
   KEY `idx_status` (`status`),
   KEY `idx_zone` (`zone_id`),
@@ -91,7 +96,9 @@ CREATE TABLE `assets` (
   CONSTRAINT `assets_ibfk_6` FOREIGN KEY (`audit_task_id`) REFERENCES `audit_tasks` (`id`) ON DELETE SET NULL,
   CONSTRAINT `assets_ibfk_7` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
   CONSTRAINT `assets_ibfk_8` FOREIGN KEY (`last_modified_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
-  CONSTRAINT `fk_asset_label_template` FOREIGN KEY (`label_template_id`) REFERENCES `label_templates` (`id`) ON DELETE SET NULL
+  CONSTRAINT `fk_asset_label_template` FOREIGN KEY (`label_template_id`) REFERENCES `label_templates` (`id`) ON DELETE SET NULL,
+  CONSTRAINT `fk_assets_belongs_to` FOREIGN KEY (`belongs_to_item`) REFERENCES `assets` (`asset_numeric_id`) ON DELETE SET NULL,
+  CONSTRAINT `fk_assets_previously_was` FOREIGN KEY (`previously_was`) REFERENCES `assets` (`asset_numeric_id`) ON DELETE SET NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;
 /*!40101 SET character_set_client = @saved_cs_client */;
 /*!50003 SET @saved_cs_client      = @@character_set_client */ ;

+ 1 - 1
backend/seckelapi/Containerfile

@@ -21,7 +21,7 @@ WORKDIR /app
 
 # Install runtime dependencies
 RUN apt-get update && \
-    apt-get install -y ca-certificates libssl3 && \
+    apt-get install -y ca-certificates libssl3 nano && \
     rm -rf /var/lib/apt/lists/*
 
 # Copy binary and config from builder

+ 19 - 0
backend/seckelapi/config/security.toml

@@ -207,4 +207,23 @@ max_limit = 50
 max_where_conditions = 5
 user_settings_access = "read-own-only"  # Students can only read their own preferences, not modify
 
+[permissions."10"]
+# Kiosk - public terminal, can only list users for login
+rollback_on_error = true
+allow_batch_operations = false
+basic_rules = [
+    "users:r",
+    "roles:r"
+]
+advanced_rules = [
+    "users.*:block",
+    "users.id:r",
+    "users.username:r",
+    "users.name:r",
+    "users.role_id:r"
+]
+max_limit = 100
+max_where_conditions = 5
+user_settings_access = "read-own-only"
+
 

Неке датотеке нису приказане због велике количине промена