28#include <boost/filesystem/operations.hpp>
43 if (!is_regular_file(exe))
46 if (!exe.empty() && is_regular_file(exe))
53 TC_LOG_FATAL(
"sql.updates",
"Didn't find any executable MySQL binary at \'{}\' or in path, correct the path in the *.conf (\"MySQLExecutable\").",
54 absolute(exe).generic_string());
63 static std::string path;
71 return "Updates.Auth";
84 "/sql/base/auth_database.sql";
98 return "Updates.World";
130 return "Updates.Character";
143 "/sql/base/characters_database.sql";
157 return "Updates.Hotfix";
195 TC_LOG_INFO(
"sql.updates",
"Database \"{}\" does not exist, do you want to create it? [yes (default) / no]: ",
199 std::getline(std::cin, answer);
200 if (!answer.empty() && !(answer.substr(0, 1) ==
"y"))
206 static Path const temp(
"create_table.sql");
209 std::ofstream file(temp.generic_string());
212 TC_LOG_FATAL(
"sql.updates",
"Failed to create temporary query file \"{}\"!", temp.generic_string());
216 file <<
"CREATE DATABASE `" << pool.
GetConnectionInfo()->
database <<
"` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci\n\n";
227 TC_LOG_FATAL(
"sql.updates",
"Failed to create database {}! Does the user (named in *.conf) have `CREATE`, `ALTER`, `DROP`, `INSERT` and `DELETE` privileges on the MySQL server?", pool.
GetConnectionInfo()->
database);
228 boost::filesystem::remove(temp);
233 boost::filesystem::remove(temp);
247 if (!is_directory(sourceDirectory))
249 TC_LOG_ERROR(
"sql.updates",
"DBUpdater: The given source directory {} does not exist, change the path to the directory where your sql directory exists (for example c:\\source\\trinitycore). Shutting down.", sourceDirectory.generic_string());
260 result = updateFetcher.Update(
261 sConfigMgr->GetBoolDefault(
"Updates.Redundancy",
true),
262 sConfigMgr->GetBoolDefault(
"Updates.AllowRehash",
true),
263 sConfigMgr->GetBoolDefault(
"Updates.ArchivedRedundancy",
false),
264 sConfigMgr->GetIntDefault(
"Updates.CleanDeadRefMaxCount", 3));
272 result.recent, result.archived);
277 TC_LOG_INFO(
"sql.updates",
">> Applied {} {}. {}", result.updated, result.updated == 1 ?
"query" :
"queries", info);
286 QueryResult const result = Retrieve(pool,
"SHOW TABLES");
287 if (result && (result->GetRowCount() > 0))
299 TC_LOG_INFO(
"sql.updates",
">> No base file provided, skipped!");
310 TC_LOG_ERROR(
"sql.updates",
">> Base file \"{}\" is missing. Try fixing it by cloning the source again.",
311 base.generic_string());
317 std::string
const filename = base.filename().generic_string();
318 std::string
const workdir = boost::filesystem::current_path().generic_string();
319 TC_LOG_ERROR(
"sql.updates",
">> File \"{}\" is missing, download it from \"https://github.com/TrinityCore/TrinityCore/releases\"" \
320 " uncompress it and place the file \"{}\" in the directory \"{}\".", filename, filename, workdir);
328 TC_LOG_INFO(
"sql.updates",
">> Applying \'{}\'...", base.generic_string());
331 ApplyFile(pool, base);
345 return pool.
Query(query.c_str());
363 std::string
const& password, std::string
const& port_or_socket, std::string
const& database, std::string
const& ssl,
366 std::vector<std::string> args;
370 args.emplace_back(
"-h" + host);
371 args.emplace_back(
"-u" + user);
373 if (!password.empty())
374 args.emplace_back(
"-p" + password);
380 args.emplace_back(
"--protocol=PIPE");
382 args.emplace_back(
"-P" + port_or_socket);
386 if (!std::isdigit(port_or_socket[0]))
389 args.emplace_back(
"-P0");
390 args.emplace_back(
"--protocol=SOCKET");
391 args.emplace_back(
"-S" + port_or_socket);
395 args.emplace_back(
"-P" + port_or_socket);
400 args.emplace_back(
"--default-character-set=utf8");
403 args.emplace_back(
"--max-allowed-packet=1GB");
405#if !defined(MARIADB_VERSION_ID) && MYSQL_VERSION_ID >= 80000
408 args.emplace_back(
"--ssl-mode=REQUIRED");
413 args.emplace_back(
"--ssl");
418 args.emplace_back(
"-e");
422 if (!database.empty())
423 args.emplace_back(database);
427 "sql.updates",
"",
true);
429 if (ret != EXIT_SUCCESS)
431 TC_LOG_FATAL(
"sql.updates",
"Applying of file \'{}\' to database \'{}\' failed!" \
432 " If you are a user, please pull the latest revision from the repository. "
433 "Also make sure you have not applied any of the databases with your sql client. "
434 "You cannot use auto-update system and import sql files from TrinityCore repository with your sql client. "
435 "If you are a developer, please fix your sql query.",
std::shared_ptr< ResultSet > QueryResult
#define TC_LOG_ERROR(filterType__,...)
#define TC_LOG_INFO(filterType__,...)
#define TC_LOG_FATAL(filterType__,...)
static std::string & corrected_path()
static bool CheckExecutable()
static std::string GetCorrectedMySQLExecutable()
static BaseLocation GetBaseLocationType()
static bool Update(DatabaseWorkerPool< T > &pool)
boost::filesystem::path Path
static QueryResult Retrieve(DatabaseWorkerPool< T > &pool, std::string const &query)
static std::string GetBaseFile()
static void Apply(DatabaseWorkerPool< T > &pool, std::string const &query)
static bool Create(DatabaseWorkerPool< T > &pool)
static std::string GetTableName()
static void ApplyFile(DatabaseWorkerPool< T > &pool, Path const &path)
static bool IsEnabled(uint32 const updateMask)
static bool Populate(DatabaseWorkerPool< T > &pool)
static std::string GetConfigEntry()
QueryResult Query(char const *sql, T *connection=nullptr)
MySQLConnectionInfo const * GetConnectionInfo() const
void DirectExecute(char const *sql)
TC_COMMON_API std::string GetSourceDirectory()
TC_COMMON_API std::string GetMySQLExecutable()
TC_COMMON_API char const * GetHotfixesDatabase()
TC_COMMON_API char const * GetFullDatabase()
std::string SearchExecutableInPath(std::string const &filename)
int StartProcess(std::string const &executable, std::vector< std::string > const &args, std::string const &logger, std::string input_file, bool secure)
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default TC string format function.
std::string port_or_socket