refactor module db importing

This commit is contained in:
uprightbass360
2025-11-16 01:32:41 -05:00
parent 05e486ae4f
commit ea908dbbcf
15 changed files with 2120 additions and 31 deletions

View File

@@ -477,19 +477,83 @@ load_sql_helper(){
err "SQL helper not found; expected manage-modules-sql.sh to be available"
}
execute_module_sql(){
SQL_EXECUTION_FAILED=0
if declare -f execute_module_sql_scripts >/dev/null 2>&1; then
echo 'Executing module SQL scripts...'
if execute_module_sql_scripts; then
echo 'SQL execution complete.'
else
echo '⚠️ Module SQL scripts reported errors'
SQL_EXECUTION_FAILED=1
fi
else
info "SQL helper did not expose execute_module_sql_scripts; skipping module SQL execution"
stage_module_sql_files(){
# Stage SQL files to AzerothCore's native update directory structure
# This replaces manual SQL execution with AzerothCore's built-in updater
local staging_dir="${MODULE_STAGING_DIR:-$MODULES_ROOT}"
local sql_manifest="$STATE_DIR/.sql-manifest.json"
if [ ! -f "$sql_manifest" ]; then
info "No SQL manifest found - no SQL files to stage"
return 0
fi
# Check if manifest has any modules with SQL
local module_count
module_count=$(python3 -c "import json; data=json.load(open('$sql_manifest')); print(len(data.get('modules', [])))" 2>/dev/null || echo "0")
if [ "$module_count" = "0" ]; then
info "No modules with SQL files to stage"
return 0
fi
info "Staging SQL for $module_count module(s)"
# Read each module from manifest and stage its SQL
local modules_json
modules_json=$(python3 -c "import json; data=json.load(open('$sql_manifest')); print('\n'.join(m['name'] for m in data['modules']))" 2>/dev/null || echo "")
if [ -z "$modules_json" ]; then
warn "Failed to parse SQL manifest"
return 1
fi
local staged_count=0
while IFS= read -r module_name; do
if [ -z "$module_name" ]; then
continue
fi
local module_path="$staging_dir/$module_name"
local acore_modules="/azerothcore/modules/$module_name"
if [ ! -d "$module_path" ]; then
warn "Module path not found: $module_path"
continue
fi
# Call stage-module-sql.sh for this module
local stage_script="${PROJECT_ROOT}/scripts/bash/stage-module-sql.sh"
if [ ! -f "$stage_script" ]; then
# Try container location
stage_script="/scripts/bash/stage-module-sql.sh"
fi
if [ -f "$stage_script" ]; then
if "$stage_script" \
--module-name "$module_name" \
--module-path "$module_path" \
--acore-path "$acore_modules"; then
((staged_count++))
fi
else
warn "SQL staging script not found: $stage_script"
fi
done <<< "$modules_json"
if [ "$staged_count" -gt 0 ]; then
ok "Staged SQL for $staged_count module(s)"
info "SQL will be applied by AzerothCore's updater on next server startup"
fi
return 0
}
execute_module_sql(){
# Legacy function - now calls staging instead of direct execution
SQL_EXECUTION_FAILED=0
stage_module_sql_files || SQL_EXECUTION_FAILED=1
}
track_module_state(){
@@ -591,13 +655,11 @@ main(){
remove_disabled_modules
install_enabled_modules
manage_configuration_files
info "SQL execution gate: MODULES_SKIP_SQL=${MODULES_SKIP_SQL:-0}"
info "SQL staging gate: MODULES_SKIP_SQL=${MODULES_SKIP_SQL:-0}"
if [ "${MODULES_SKIP_SQL:-0}" = "1" ]; then
info "Skipping module SQL execution (MODULES_SKIP_SQL=1)"
info "Skipping module SQL staging (MODULES_SKIP_SQL=1)"
else
info "Initiating module SQL helper"
load_sql_helper
info "SQL helper loaded from ${SQL_HELPER_PATH:-unknown}"
info "Staging module SQL files for AzerothCore updater"
execute_module_sql
fi
track_module_state