Files
2026-09-12 21:13:31 +04:00

41 lines
2.2 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
db_user="${DB_USER:-sylvania}"
db_password="${DB_PASSWORD:-sylvania}"
# Identifiers are deliberately fixed; only the application login is configurable.
mariadb --default-character-set=utf8mb4 --protocol=socket -uroot -p"${MARIADB_ROOT_PASSWORD}" <<SQL
CREATE DATABASE IF NOT EXISTS auth CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE IF NOT EXISTS characters CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE IF NOT EXISTS world CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE IF NOT EXISTS hotfixes CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE IF NOT EXISTS shop CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER IF NOT EXISTS '${db_user}'@'%' IDENTIFIED BY '${db_password}';
GRANT ALL PRIVILEGES ON auth.* TO '${db_user}'@'%';
GRANT ALL PRIVILEGES ON characters.* TO '${db_user}'@'%';
GRANT ALL PRIVILEGES ON world.* TO '${db_user}'@'%';
GRANT ALL PRIVILEGES ON hotfixes.* TO '${db_user}'@'%';
GRANT ALL PRIVILEGES ON shop.* TO '${db_user}'@'%';
FLUSH PRIVILEGES;
SQL
mariadb --default-character-set=utf8mb4 --protocol=socket -uroot -p"${MARIADB_ROOT_PASSWORD}" auth < /sylvania/base/auth_database.sql
mariadb --default-character-set=utf8mb4 --protocol=socket -uroot -p"${MARIADB_ROOT_PASSWORD}" characters < /sylvania/base/characters_database.sql
mariadb --default-character-set=utf8mb4 --protocol=socket -uroot -p"${MARIADB_ROOT_PASSWORD}" shop < /sylvania/base/shop_database.sql
shopt -s nullglob
for dump in /sylvania/dumps/*.sql /sylvania/dumps/*.sql.gz; do
echo "Importing game database dump: ${dump}"
if [[ "${dump}" == *.gz ]]; then
gzip -dc "${dump}" | mariadb --default-character-set=utf8mb4 --protocol=socket -uroot -p"${MARIADB_ROOT_PASSWORD}"
else
mariadb --default-character-set=utf8mb4 --protocol=socket -uroot -p"${MARIADB_ROOT_PASSWORD}" < "${dump}"
fi
done
# The published 7.3.5 dump uses a lowercase name, while the core queries this
# one legacy table with its historical mixed-case identifier on Linux.
mariadb --default-character-set=utf8mb4 --protocol=socket -uroot -p"${MARIADB_ROOT_PASSWORD}" \
-e 'RENAME TABLE hotfixes.questv2clitask TO hotfixes.QuestV2CliTask;'