mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2025-11-29 17:38:24 +08:00
refactor(db-scripts): replace PowerShell database tools with Bash scripts and update documentation (#22372)
* closes https://github.com/azerothcore/azerothcore-wotlk/issues/4343 This pull request replaces the PowerShell implementation of the AzerothCore database export and squash tools with Bash scripts, streamlining the process and improving compatibility. It also updates the documentation to reflect these changes. The most important changes include the creation of new Bash scripts for exporting databases, squashing databases, and updating versions, as well as the removal of the previous PowerShell script and its associated documentation. ### Script Replacement and Enhancements: * [`apps/DatabaseSquash/DatabaseExporter/DatabaseExporter.sh`](diffhunk://#diff-af0bd252ac095aaad91b842c75b60a689792e6dc9ce88f5e2e4b6f68acf84dcaR1-R69): Introduced a Bash script to replace the PowerShell implementation for exporting database tables, with added features such as formatted SQL output and dynamic directory creation. * [`apps/DatabaseSquash/DatabaseSquash.sh`](diffhunk://#diff-79ff4f749c045a7d91e9b43aefb5d6fbebdc5fdfb430fbcba329e4d96d71a4fbR1-R52): Added a Bash script to automate the database squash process, integrating the version updater and database exporter tools. * [`apps/DatabaseSquash/VersionUpdater/VersionUpdater.sh`](diffhunk://#diff-3abc69c645cb80aff30824739e317c9e847e743eeab15ab4825951d10179b265R1-R84): Created a Bash script for automatically updating the version in `acore.json` and generating SQL update files with proper versioning. ### Documentation Updates: * [`apps/DatabaseSquash/DatabaseExporter/databaseexporter.md`](diffhunk://#diff-b2b291286f2b900a022474f00754ebfe78410780c010d46752335a372d688aefR1-R16): Rewritten documentation to reflect the usage of the new Bash script for database exporting. * [`apps/DatabaseSquash/VersionUpdater/versionupdater.md`](diffhunk://#diff-f12e21f8a404957c90d9120cf9df0724ff27a7efdb5de0798d974079cfe8adadR1-R10): Added documentation for the new version updater tool, explaining its functionality and usage. * [`apps/DatabaseSquash/databasesquash.md`](diffhunk://#diff-4a559f6e7404b529714bac65ad22744feb7b9f88343864a20e0a46974233767eR1-R11): Documented the overall database squash tool, detailing its integration of the version updater and database exporter scripts. ### Removal of Legacy Code: * [`apps/DatabaseExporter/DatabaseExporter.ps1`](diffhunk://#diff-2b4e49f704d88a372b5160c7278839668c81dbecaf52a4edd327873e30b9ae70L1-L234): Removed the PowerShell script for database exporting, along with its associated functionality and settings. * [`apps/DatabaseExporter/databaseexporter.md`](diffhunk://#diff-0618d62def0d611be6e0d4fc524df6f702f493cb87870d9382402aaf52f484e8L1-L85): Deleted outdated documentation for the PowerShell-based database exporter tool.
This commit is contained in:
69
apps/DatabaseSquash/DatabaseExporter/DatabaseExporter.sh
Normal file
69
apps/DatabaseSquash/DatabaseExporter/DatabaseExporter.sh
Normal file
@@ -0,0 +1,69 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
|
||||
|
||||
if [[ "$PROJECT_ROOT" =~ ^/([a-zA-Z])/(.*) ]]; then
|
||||
DRIVE_LETTER="${BASH_REMATCH[1]}"
|
||||
PATH_REMAINDER="${BASH_REMATCH[2]}"
|
||||
PROJECT_ROOT="${DRIVE_LETTER^^}:/${PATH_REMAINDER}"
|
||||
fi
|
||||
|
||||
BASE_OUTPUT_DIR="$PROJECT_ROOT/data/sql/base"
|
||||
|
||||
read -p "Enter MySQL username: " DB_USER
|
||||
read -p "Enter MySQL password: " DB_PASS
|
||||
read -p "Enter MySQL host (default: localhost): " DB_HOST
|
||||
DB_HOST=${DB_HOST:-localhost}
|
||||
read -p "Enter MySQL port (default: 3306): " DB_PORT
|
||||
DB_PORT=${DB_PORT:-3306}
|
||||
|
||||
# Prompt for database names
|
||||
read -p "Enter name of Auth database [default: acore_auth]: " DB_AUTH
|
||||
DB_AUTH=${DB_AUTH:-acore_auth}
|
||||
read -p "Enter name of Characters database [default: acore_characters]: " DB_CHARACTERS
|
||||
DB_CHARACTERS=${DB_CHARACTERS:-acore_characters}
|
||||
read -p "Enter name of World database [default: acore_world]: " DB_WORLD
|
||||
DB_WORLD=${DB_WORLD:-acore_world}
|
||||
|
||||
# Mapping for folder names
|
||||
declare -A DB_MAP=(
|
||||
["$DB_AUTH"]="db_auth"
|
||||
["$DB_CHARACTERS"]="db_characters"
|
||||
["$DB_WORLD"]="db_world"
|
||||
)
|
||||
|
||||
# Dump each database
|
||||
for DB_NAME in "${!DB_MAP[@]}"; do
|
||||
FOLDER_NAME="${DB_MAP[$DB_NAME]}"
|
||||
echo "📦 Dumping database '$DB_NAME' into folder '$FOLDER_NAME'"
|
||||
echo "$BASE_OUTPUT_DIR/$FOLDER_NAME"
|
||||
mkdir -p "$BASE_OUTPUT_DIR/$FOLDER_NAME"
|
||||
|
||||
TABLES=$(mysql -u "$DB_USER" -p"$DB_PASS" -h "$DB_HOST" -P "$DB_PORT" -N -e "SHOW TABLES FROM \`$DB_NAME\`;")
|
||||
|
||||
if [[ -z "$TABLES" ]]; then
|
||||
echo "⚠️ No tables found or failed to connect to '$DB_NAME'. Skipping."
|
||||
continue
|
||||
fi
|
||||
|
||||
while IFS= read -r raw_table; do
|
||||
TABLE=$(echo "$raw_table" | tr -d '\r"' | xargs)
|
||||
if [[ -n "$TABLE" ]]; then
|
||||
echo " ➤ Dumping table: $TABLE"
|
||||
mysqldump -u $DB_USER -p$DB_PASS -h $DB_HOST -P $DB_PORT --extended-insert $DB_NAME $TABLE > $BASE_OUTPUT_DIR/$FOLDER_NAME/$TABLE.sql
|
||||
|
||||
# cleanup files
|
||||
sed -E '
|
||||
s/VALUES[[:space:]]*/VALUES\n/;
|
||||
:a
|
||||
s/\),\(/\),\n\(/g;
|
||||
ta
|
||||
' "$BASE_OUTPUT_DIR/$FOLDER_NAME/$TABLE.sql" > "$BASE_OUTPUT_DIR/$FOLDER_NAME/${TABLE}_formatted.sql"
|
||||
mv "$BASE_OUTPUT_DIR/$FOLDER_NAME/${TABLE}_formatted.sql" "$BASE_OUTPUT_DIR/$FOLDER_NAME/$TABLE.sql"
|
||||
fi
|
||||
done <<< "$TABLES"
|
||||
done
|
||||
|
||||
echo "✅ Done dumping all specified databases."
|
||||
Reference in New Issue
Block a user