new version commit
This commit is contained in:
70
apps/DatabaseSquash/DatabaseExporter/DatabaseExporter.sh
Normal file
70
apps/DatabaseSquash/DatabaseExporter/DatabaseExporter.sh
Normal file
@@ -0,0 +1,70 @@
|
||||
#!/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"
|
||||
# --skip-tz-utc needed to keep TIMESTAMP values as-is
|
||||
mysqldump -u $DB_USER -p$DB_PASS -h $DB_HOST -P $DB_PORT --skip-tz-utc --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."
|
||||
16
apps/DatabaseSquash/DatabaseExporter/databaseexporter.md
Normal file
16
apps/DatabaseSquash/DatabaseExporter/databaseexporter.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# The AzerothCore Database Exporter for Database Squashes
|
||||
|
||||
> [!CAUTION]
|
||||
> These steps are only for project maintainers who intend to update base files.
|
||||
|
||||
## Requirements
|
||||
|
||||
1. MySQL
|
||||
2. mysqldump
|
||||
|
||||
## Usage
|
||||
|
||||
1. Run DatabaseExporter.sh from the current directory.
|
||||
2. Fill in required data within the CLI.
|
||||
3. The tool will autopopulate the basefile directories.
|
||||
4. Done.
|
||||
52
apps/DatabaseSquash/DatabaseSquash.sh
Normal file
52
apps/DatabaseSquash/DatabaseSquash.sh
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
echo "❗CAUTION"
|
||||
echo "This tool is only supposed to be used by AzerothCore Maintainers."
|
||||
echo "The tool is used to prepare for, and generate a database squash."
|
||||
echo
|
||||
echo "Before you continue make sure you have read"
|
||||
echo "https://github.com/azerothcore/azerothcore-wotlk/blob/master/data/sql/base/database-squash.md"
|
||||
echo
|
||||
read -p "Are you sure you want to continue (Y/N)?" choice
|
||||
case "$choice" in
|
||||
y|Y ) echo "Starting...";;
|
||||
* ) echo "Aborted"; exit 0 ;;
|
||||
esac
|
||||
|
||||
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
|
||||
|
||||
VERSION_UPDATER_PATH="$PROJECT_ROOT/apps/DatabaseSquash/VersionUpdater/versionupdater.sh"
|
||||
|
||||
"$VERSION_UPDATER_PATH"
|
||||
|
||||
echo "✅ VersionUpdater Completed..."
|
||||
echo
|
||||
echo "❗IMPORTANT!"
|
||||
echo "1. Before you continue you need to drop all your databases."
|
||||
echo "2. Run WorldServer to populate the database."
|
||||
echo
|
||||
echo "❗DO NOT continue before you have completed the steps above!"
|
||||
echo
|
||||
echo "The next step will export your database and overwrite the base files."
|
||||
echo
|
||||
read -p "Are you sure you want to export your database (Y/N)?" choice
|
||||
case "$choice" in
|
||||
y|Y ) echo "Starting...";;
|
||||
* ) echo "Aborted"; exit 0 ;;
|
||||
esac
|
||||
|
||||
DATABASE_EXPORTER_PATH="$PROJECT_ROOT/apps/DatabaseSquash/DatabaseExporter/databaseexporter.sh"
|
||||
|
||||
"$DATABASE_EXPORTER_PATH"
|
||||
|
||||
echo "✅ DatabaseExporter Completed..."
|
||||
echo "✅ DatabaseSquash Completed... "
|
||||
echo
|
||||
read -p "Press Enter to exit..."
|
||||
84
apps/DatabaseSquash/VersionUpdater/VersionUpdater.sh
Normal file
84
apps/DatabaseSquash/VersionUpdater/VersionUpdater.sh
Normal file
@@ -0,0 +1,84 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
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
|
||||
|
||||
ACORE_JSON_PATH="$PROJECT_ROOT/acore.json"
|
||||
DB_WORLD_UPDATE_DIR="$PROJECT_ROOT/data/sql/updates/db_world"
|
||||
|
||||
VERSION_LINE=$(grep '"version"' "$ACORE_JSON_PATH")
|
||||
VERSION=$(echo "$VERSION_LINE" | sed -E 's/.*"version": *"([^"]+)".*/\1/')
|
||||
|
||||
# Parse version into parts
|
||||
if [[ "$VERSION" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(.*)$ ]]; then
|
||||
MAJOR="${BASH_REMATCH[1]}"
|
||||
SUFFIX="${BASH_REMATCH[4]}"
|
||||
NEW_VERSION="$((MAJOR + 1)).0.0$SUFFIX"
|
||||
|
||||
# Replace version in file
|
||||
sed -i.bak -E "s/(\"version\": *\")[^\"]+(\" *)/\1$NEW_VERSION\2/" "$ACORE_JSON_PATH"
|
||||
rm -f "$ACORE_JSON_PATH.bak"
|
||||
|
||||
echo "✅ Version updated to $NEW_VERSION"
|
||||
else
|
||||
echo "Error: Could not parse version string: $VERSION"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract the new major version from NEW_VERSION
|
||||
if [[ "$NEW_VERSION" =~ ^([0-9]+)\. ]]; then
|
||||
NEW_MAJOR="${BASH_REMATCH[1]}"
|
||||
else
|
||||
echo "Error: Unable to extract major version from $NEW_VERSION"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Prepare SQL content
|
||||
DB_VERSION_CONTENT="'ACDB 335.${NEW_MAJOR}-dev'"
|
||||
SQL_QUERY="UPDATE \`version\` SET \`db_version\`=${DB_VERSION_CONTENT}, \`cache_id\`=${NEW_MAJOR} LIMIT 1;"
|
||||
|
||||
# Format date as yyyy_mm_dd
|
||||
TODAY=$(date +%Y_%m_%d)
|
||||
|
||||
# Ensure directory exists
|
||||
mkdir -p "$DB_WORLD_UPDATE_DIR"
|
||||
|
||||
# List existing files for today
|
||||
existing_files=($(find "$DB_WORLD_UPDATE_DIR" -maxdepth 1 -type f -name "${TODAY}_*.sql" 2>/dev/null))
|
||||
|
||||
# Determine next xx counter
|
||||
# Determine next xx
|
||||
COUNTER="00"
|
||||
if [ ${#existing_files[@]} -gt 0 ]; then
|
||||
max=0
|
||||
for file in "${existing_files[@]}"; do
|
||||
basename=$(basename "$file")
|
||||
if [[ "$basename" =~ ^${TODAY}_([0-9]{2})\.sql$ ]]; then
|
||||
num=${BASH_REMATCH[1]}
|
||||
if [[ "$num" =~ ^[0-9]+$ ]] && (( 10#$num > max )); then
|
||||
max=$((10#$num))
|
||||
fi
|
||||
fi
|
||||
done
|
||||
COUNTER=$(printf "%02d" $((max + 1)))
|
||||
fi
|
||||
|
||||
# Compose final file path
|
||||
SQL_FILENAME="${TODAY}_${COUNTER}.sql"
|
||||
SQL_FILE_PATH="$DB_WORLD_UPDATE_DIR/$SQL_FILENAME"
|
||||
|
||||
# Write to file
|
||||
{
|
||||
echo "-- Auto-generated by VersionUpdater.sh on $(date)"
|
||||
echo "$SQL_QUERY"
|
||||
} > "$SQL_FILE_PATH"
|
||||
|
||||
echo "✅ SQL file created at $SQL_FILE_PATH"
|
||||
10
apps/DatabaseSquash/VersionUpdater/versionupdater.md
Normal file
10
apps/DatabaseSquash/VersionUpdater/versionupdater.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# The AzerothCore Version Updater for Database Squashes
|
||||
|
||||
> [!CAUTION]
|
||||
> These steps are only for project maintainers who intend to update base files.
|
||||
|
||||
## Usage
|
||||
|
||||
1. Run VersionUpdater.sh from the current directory.
|
||||
2. The tool will update acore.json and create a new update sql file.
|
||||
3. Done.
|
||||
11
apps/DatabaseSquash/databasesquash.md
Normal file
11
apps/DatabaseSquash/databasesquash.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# The AzerothCore DatabaseSquash tool for Database Squashes
|
||||
|
||||
> [!CAUTION]
|
||||
> These steps are only for project maintainers who intend to update base files.
|
||||
|
||||
## Usage
|
||||
|
||||
1. Run DatabaseSquash.sh from the current directory.
|
||||
2. The tool will run VersionUpdater.sh and DatabaseExporter.sh
|
||||
3. Follow the instructions in the CLI.
|
||||
4. Done.
|
||||
Reference in New Issue
Block a user