#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ENV_FILE="${ENV_FILE:-$ROOT_DIR/.env}" if [[ -f "$ENV_FILE" ]]; then set -a # shellcheck disable=SC1090 source "$ENV_FILE" set +a fi IMPORT_MYTHICPLUS_SQL="${ACORE_IMPORT_MYTHICPLUS_SQL:-1}" usage() { cat <&2 exit 1 fi log "importing $(basename "$file_path") into ${database}" docker compose exec -T ac-database bash -lc \ "mysql -uroot -p\"\$MYSQL_ROOT_PASSWORD\" \"$database\"" < "$file_path" } require_integer_flag() { local name="$1" local value="$2" if ! [[ "$value" =~ ^[01]$ ]]; then printf '%s must be 0 or 1, got: %s\n' "$name" "$value" >&2 exit 1 fi } maybe_import_table() { local database="$1" local table_name="$2" local file_path="$3" if table_exists "$database" "$table_name"; then log "table ${database}.${table_name} already exists, skipping" return 0 fi import_sql_file "$database" "$file_path" } if (($# > 0)); then case "$1" in -h|--help) usage exit 0 ;; *) printf 'Unknown option: %s\n\n' "$1" >&2 usage >&2 exit 1 ;; esac fi require_integer_flag "ACORE_IMPORT_MYTHICPLUS_SQL" "$IMPORT_MYTHICPLUS_SQL" cd "$ROOT_DIR" if ! docker compose ps --status running --services | grep -qx 'ac-database'; then printf 'ac-database is not running. Start the database first.\n' >&2 exit 1 fi if [[ "$IMPORT_MYTHICPLUS_SQL" == "0" ]]; then log "MythicPlus SQL import disabled, skipped" exit 0 fi if [[ ! -d "$ROOT_DIR/sql/Mythic+" ]]; then log "sql/Mythic+ directory not found, skipped" exit 0 fi maybe_import_table "acore_characters" "character_mythic_history" \ "$ROOT_DIR/sql/Mythic+/characters/character_mythic_history.sql" maybe_import_table "acore_characters" "character_mythic_keys" \ "$ROOT_DIR/sql/Mythic+/characters/character_mythic_keys.sql" maybe_import_table "acore_characters" "character_mythic_rating" \ "$ROOT_DIR/sql/Mythic+/characters/character_mythic_rating.sql" maybe_import_table "acore_characters" "character_mythic_vault" \ "$ROOT_DIR/sql/Mythic+/characters/character_mythic_vault.sql" maybe_import_table "acore_characters" "character_mythic_weekly_affixes" \ "$ROOT_DIR/sql/Mythic+/characters/character_mythic_weekly_affixes.sql" maybe_import_table "acore_world" "world_mythic_loot" \ "$ROOT_DIR/sql/Mythic+/world/world_mythic_loot.sql" maybe_import_table "acore_world" "world_vault_loot" \ "$ROOT_DIR/sql/Mythic+/world/world_vault_loot.sql" if [[ "$(mysql_query "acore_world" "SELECT COUNT(*) FROM creature_template WHERE entry = 900001;")" == "0" ]]; then import_sql_file "acore_world" "$ROOT_DIR/sql/Mythic+/world/creature_and_keystones.sql" else log "MythicPlus creature bootstrap already exists, skipping" fi log "custom SQL bootstrap completed"