-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfix-modules-sql.sh
More file actions
158 lines (145 loc) · 5.56 KB
/
fix-modules-sql.sh
File metadata and controls
158 lines (145 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
# Script to automatically import all SQL files from AzerothCore modules
# Searches for SQL files in modules/*/data/sql/ and modules/*/sql/ directories and imports them to appropriate databases
set -e
MODULES_DIR="$HOME/azerothcore-android/modules"
DB_USER="acore"
DB_PASS="acore"
echo "=== AzerothCore Module SQL Import Script ==="
echo "Searching for SQL files in: $MODULES_DIR"
echo ""
# Function to import SQL file
import_sql() {
local file="$1"
local database="$2"
local relative_path="$3"
echo " Importing: $relative_path -> $database"
if mariadb -u "$DB_USER" -p"$DB_PASS" "$database" < "$file" 2>/dev/null; then
echo " ✓ Success"
else
echo " ❌ Failed"
return 1
fi
}
# Check if modules directory exists
if [ ! -d "$MODULES_DIR" ]; then
echo "Error: Modules directory not found at $MODULES_DIR"
exit 1
fi
# Find all modules with SQL data (check both data/sql and sql directories)
modules_with_sql=$(find "$MODULES_DIR" -type d \( -path "*/data/sql" -o -path "*/sql" \) | sed -E 's|/(data/)?sql$||' | sort -u)
if [ -z "$modules_with_sql" ]; then
echo "No modules with SQL data found."
exit 0
fi
echo "Found modules with SQL data:"
echo "$modules_with_sql" | sed 's|.*/||' | sed 's/^/ - /'
echo ""
# Process each module
total_files=0
success_count=0
failed_count=0
for module_dir in $modules_with_sql; do
module_name=$(basename "$module_dir")
# Check for both possible SQL directory locations
sql_dir=""
if [ -d "$module_dir/data/sql" ]; then
sql_dir="$module_dir/data/sql"
echo "Processing module: $module_name (using data/sql)"
elif [ -d "$module_dir/sql" ]; then
sql_dir="$module_dir/sql"
echo "Processing module: $module_name (using sql)"
else
echo "Warning: No SQL directory found for module $module_name"
continue
fi
# Find all SQL files in this module
if [ -d "$sql_dir" ]; then
# Find all db-* directories and process them
db_dirs=$(find "$sql_dir" -type d -name "db-*" 2>/dev/null | sort || true)
for db_dir in $db_dirs; do
db_type=$(basename "$db_dir" | sed 's/^db-//')
# Map db type to actual database name
case "$db_type" in
"auth")
target_db="acore_auth"
;;
"characters")
target_db="acore_characters"
;;
"world")
target_db="acore_world"
;;
*)
# For any other db-* directories, try to map to acore_*
target_db="acore_$db_type"
;;
esac
# Find SQL files in this db directory
sql_files=$(find "$db_dir" -name "*.sql" 2>/dev/null || true)
if [ -n "$sql_files" ]; then
echo " Database '$target_db' files:"
while IFS= read -r file; do
if [ -f "$file" ]; then
relative_path="${file#$MODULES_DIR/}"
total_files=$((total_files + 1))
if import_sql "$file" "$target_db" "$relative_path"; then
success_count=$((success_count + 1))
else
failed_count=$((failed_count + 1))
fi
fi
done <<< "$sql_files"
fi
done
# Also check for alternative directory structures (world/, characters/, auth/)
alt_dirs=$(find "$sql_dir" -type d \( -name "world" -o -name "characters" -o -name "auth" \) 2>/dev/null | sort || true)
for alt_dir in $alt_dirs; do
dir_type=$(basename "$alt_dir")
# Map directory type to actual database name
case "$dir_type" in
"auth")
target_db="acore_auth"
;;
"characters")
target_db="acore_characters"
;;
"world")
target_db="acore_world"
;;
esac
# Find SQL files in this directory (including subdirectories)
sql_files=$(find "$alt_dir" -name "*.sql" 2>/dev/null || true)
if [ -n "$sql_files" ]; then
echo " Database '$target_db' files (alt structure):"
while IFS= read -r file; do
if [ -f "$file" ]; then
relative_path="${file#$MODULES_DIR/}"
total_files=$((total_files + 1))
if import_sql "$file" "$target_db" "$relative_path"; then
success_count=$((success_count + 1))
else
failed_count=$((failed_count + 1))
fi
fi
done <<< "$sql_files"
fi
done
fi
echo ""
done
echo "=== Import Summary ==="
echo "Total files processed: $total_files"
echo "Successful imports: $success_count"
echo "Failed imports: $failed_count"
if [ $failed_count -gt 0 ]; then
echo ""
echo "Some imports failed. This might be normal if:"
echo " - Files contain updates for non-existent tables"
echo " - Files are meant for different AzerothCore versions"
echo " - Dependencies between files exist"
exit 1
else
echo ""
echo "All SQL files imported successfully!"
fi