chore(scripts): add world-db-from-base.sh for clean acore_world from base
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Executable
+66
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env bash
|
||||
# Rebuild acore_world from data/sql/base/db_world only (AzerothCore "shortcut"):
|
||||
# the shipped base `updates` table already records archived migrations as applied,
|
||||
# so worldserver only needs to run pending files under data/sql/updates/db_world
|
||||
# (and your custom/pending paths if used).
|
||||
#
|
||||
# Usage:
|
||||
# export MYSQL_PWD='...'
|
||||
# ./scripts/world-db-from-base.sh -h 10.0.13.252 -u acore -D acore_world
|
||||
#
|
||||
# Requires: mysql client. Optional: pass --force to skip confirmation.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 -h HOST -u USER -D DATABASE [--port PORT] [--force]" >&2
|
||||
echo " Or set: MYSQL_HOST MYSQL_USER MYSQL_DATABASE [MYSQL_PWD in env]" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
HOST="${MYSQL_HOST:-}"
|
||||
USER="${MYSQL_USER:-}"
|
||||
DBNAME="${MYSQL_DATABASE:-}"
|
||||
PORT="${MYSQL_PORT:-3306}"
|
||||
FORCE=0
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-h) HOST="$2"; shift 2 ;;
|
||||
-u) USER="$2"; shift 2 ;;
|
||||
-D) DBNAME="$2"; shift 2 ;;
|
||||
--port) PORT="$2"; shift 2 ;;
|
||||
--force) FORCE=1; shift ;;
|
||||
*) usage ;;
|
||||
esac
|
||||
done
|
||||
|
||||
: "${HOST:?set -h or MYSQL_HOST}"
|
||||
: "${USER:?set -u or MYSQL_USER}"
|
||||
: "${DBNAME:?set -D or MYSQL_DATABASE}"
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
BASE_DIR="$REPO_ROOT/data/sql/base/db_world"
|
||||
|
||||
if [[ ! -d "$BASE_DIR" ]]; then
|
||||
echo "Base directory not found: $BASE_DIR" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$FORCE" -ne 1 ]]; then
|
||||
read -r -p "DESTROY database '$DBNAME' on $HOST and rebuild from base? [yes/no]: " ans
|
||||
[[ "$ans" == "yes" ]] || { echo "Aborted."; exit 1; }
|
||||
fi
|
||||
|
||||
MYSQL=(mysql -h "$HOST" -P "$PORT" -u "$USER" --protocol=tcp)
|
||||
"${MYSQL[@]}" -e "DROP DATABASE IF EXISTS \`$DBNAME\`; CREATE DATABASE \`$DBNAME\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
||||
|
||||
mapfile -t SQL_FILES < <(find "$BASE_DIR" -maxdepth 1 -name '*.sql' -printf '%f\n' | sort)
|
||||
|
||||
for f in "${SQL_FILES[@]}"; do
|
||||
echo ">> $f"
|
||||
"${MYSQL[@]}" "$DBNAME" <"$BASE_DIR/$f"
|
||||
done
|
||||
|
||||
echo ">> Done. Start worldserver once; it should report World DB up-to-date or only apply updates/db_world."
|
||||
Reference in New Issue
Block a user