Upgrading checks for Database::CheckDatabaseVersion (#86)

Improved messages for DB checks errors in Database.cpp
Remove code duplication for sLog.outErrorDb()
Rename some variables for better code understanding

Change tabs with spaces
This commit is contained in:
Elmsroth 2020-05-09 08:07:40 +02:00 committed by GitHub
parent c762a4118f
commit 96e447cadf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,7 +40,7 @@ struct DBVersion
std::string dbname;
uint32 expected_version;
uint32 expected_structure;
uint32 expected_content;
uint32 minimal_expected_content; // Minimal because core can starts with some missing contents
std::string description;
};
@ -534,83 +534,108 @@ bool Database::RollbackTransaction()
return true;
}
// TODO : Depending on the case do not use Error but Warning, so will need to ad a function pointer in args
void PrintYouHaveDatabaseVersion(uint32 current_db_version, uint32 current_db_structure, uint32 current_db_content, std::string description)
{
sLog.outErrorDb(" [A] You have database Version: %u", current_db_version);
sLog.outErrorDb(" Structure: %u", current_db_structure);
sLog.outErrorDb(" Content: %u", current_db_content);
sLog.outErrorDb(" Description: %s", description.c_str());
}
// TODO : Depending on the case do not use Error but Warning, so will need to ad a function pointer in args
void PrintYouNeedDatabaseVersionExpectedByCore(const DBVersion& core_db_requirements)
{
sLog.outErrorDb(" [B] The core needs database Version: %u", core_db_requirements.expected_version);
sLog.outErrorDb(" Structure: %u", core_db_requirements.expected_structure);
sLog.outErrorDb(" Content: %u", core_db_requirements.minimal_expected_content);
sLog.outErrorDb(" Description: %s", core_db_requirements.description.c_str());
}
bool Database::CheckDatabaseVersion(DatabaseTypes database)
{
const DBVersion& dbversion = databaseVersions[database];
const DBVersion& core_db_requirements = databaseVersions[database];
// Fetch the database version table information
QueryResult* result = Query("SELECT `version`, `structure`, `content`, `description` FROM `db_version` ORDER BY `version` DESC, `structure` DESC, `content` DESC LIMIT 1");
// db_version table does not exist or is empty
if (!result)
{
sLog.outErrorDb("The table `db_version` in your [%s] database is missing or corrupt.", dbversion.dbname.c_str());
sLog.outErrorDb("The table `db_version` in your [%s] database is missing or corrupt.", core_db_requirements.dbname.c_str());
sLog.outErrorDb();
sLog.outErrorDb(" [A] You have database Version: MaNGOS can not verify your database version or its existence!");
sLog.outErrorDb();
sLog.outErrorDb(" [B] You need database Version: %u", dbversion.expected_version);
sLog.outErrorDb(" Structure: %u", dbversion.expected_structure);
sLog.outErrorDb(" Content: %u", dbversion.expected_content);
sLog.outErrorDb(" Description: %s", dbversion.description.c_str());
PrintYouNeedDatabaseVersionExpectedByCore(core_db_requirements);
sLog.outErrorDb();
sLog.outErrorDb("Please verify your database location or your database integrity.");
// The core loading will no go further :
return false;
}
Field* fields = result->Fetch();
uint32 version = fields[0].GetUInt32();
uint32 structure = fields[1].GetUInt32();
uint32 content = fields[2].GetUInt32();
uint32 current_db_version = fields[0].GetUInt32();
uint32 current_db_structure = fields[1].GetUInt32();
uint32 current_db_content = fields[2].GetUInt32();
std::string description = fields[3].GetCppString();
delete result;
// Structure does not match the required version
if (version != dbversion.expected_version || structure != dbversion.expected_structure)
if (current_db_version != core_db_requirements.expected_version || current_db_structure != core_db_requirements.expected_structure)
{
sLog.outErrorDb("The table `db_version` indicates that your [%s] database does not match the expected structure!", dbversion.dbname.c_str());
sLog.outErrorDb("The table `db_version` indicates that your [%s] database does not match the expected structure!", core_db_requirements.dbname.c_str());
sLog.outErrorDb();
sLog.outErrorDb(" [A] You have database Version: %u", version);
sLog.outErrorDb(" Structure: %u", structure);
sLog.outErrorDb(" Content: %u", content);
sLog.outErrorDb(" Description: %s", description.c_str());
PrintYouHaveDatabaseVersion(current_db_version, current_db_structure, current_db_content, description);
sLog.outErrorDb();
sLog.outErrorDb(" [B] You need database Version: %u", dbversion.expected_version);
sLog.outErrorDb(" Structure: %u", dbversion.expected_structure);
sLog.outErrorDb(" Content: %u", dbversion.expected_content);
sLog.outErrorDb(" Description: %s", dbversion.description.c_str());
PrintYouNeedDatabaseVersionExpectedByCore(core_db_requirements);
sLog.outErrorDb();
sLog.outErrorDb("You must apply all updates after [A] to [B] to use MaNGOS with this database.");
sLog.outErrorDb("These updates are included in the database/%s/Updates folder.", dbversion.dbname.c_str());
sLog.outErrorDb("These updates are included in the database/%s/Updates folder.", core_db_requirements.dbname.c_str());
return false;
}
// DB is not up to date, but structure is correct. Send warning but start core
if (content > dbversion.expected_content)
bool db_vs_core_content_version_mismatch = false;
// DB is not up to date, but structure is correct.
// The 'content' version in the 'db_version' table can be < from the one required by the core
// See enum values for :
// WORLD_DB_CONTENT_NR
// CHAR_DB_CONTENT_NR
// REALMD_DB_CONTENT_NR
// for more information.
if (current_db_content < core_db_requirements.minimal_expected_content)
{
sLog.outErrorDb("You have not updated the core for few DB [%s] updates!", dbversion.dbname.c_str());
sLog.outErrorDb("Current DB content is %u, core expects %u", content, dbversion.expected_content);
sLog.outErrorDb("This is ok for now but should not last long.");
}
else if (content != dbversion.expected_content)
{
sLog.outErrorDb("The table `db_version` indicates that your [%s] database does not match the expected version!", dbversion.dbname.c_str());
sLog.outErrorDb();
sLog.outErrorDb(" [A] You have database Version: %u", version);
sLog.outErrorDb(" Structure: %u", structure);
sLog.outErrorDb(" Content: %u", content);
sLog.outErrorDb(" Description: %s", description.c_str());
sLog.outErrorDb();
sLog.outErrorDb(" [B] You need database Version: %u", dbversion.expected_version);
sLog.outErrorDb(" Structure: %u", dbversion.expected_structure);
sLog.outErrorDb(" Content: %u", dbversion.expected_content);
sLog.outErrorDb(" Description: %s", dbversion.description.c_str());
sLog.outErrorDb();
sLog.outErrorDb("You are missing content updates or you have content updates beyond the expected core version.");
// TODO : Should not display with error color but warning (e.g YELLOW) => Create a sLog.outWarningDb() and sLog.outWarning()
sLog.outErrorDb("You have not updated the core for few DB [%s] updates!", core_db_requirements.dbname.c_str());
sLog.outErrorDb("Current DB content is %u, core expects %u", current_db_content, core_db_requirements.minimal_expected_content);
sLog.outErrorDb("It is recommended to run ALL database updates up to the required core version.");
sLog.outErrorDb("These updates are included in the database/%s/Updates folder.", dbversion.dbname.c_str());
sLog.outErrorDb("These updates are included in the database/%s/Updates folder.", core_db_requirements.dbname.c_str());
sLog.outErrorDb("This is ok for now but should not last long.");
db_vs_core_content_version_mismatch = true;
}
// Else if the 'content' version in the 'db_version' table is > to the on expected by the core
else if (current_db_content > core_db_requirements.minimal_expected_content)
{
// TODO : Should not display with error color but warning (e.g YELLOW) => Create a sLog.outWarningDb() and sLog.outWarning()
sLog.outErrorDb("You have content updates beyond the expected core version.");
sLog.outErrorDb("Check if the core you are running is built from the latest sources.");
sLog.outErrorDb("If so, DO NOT PANIC ! This message will disappear when the next DB Roll-Up will be released.");
db_vs_core_content_version_mismatch = true;
};
// In anys cases if there are differences in content : output a recap of the differences :
if (db_vs_core_content_version_mismatch)
{
// TODO : Should not display with error color but warning (e.g YELLOW) => Create a sLog.outWarningDb() and sLog.outWarning()
sLog.outErrorDb("The table `db_version` indicates that your [%s] database does not match the expected version!", core_db_requirements.dbname.c_str());
sLog.outErrorDb();
PrintYouHaveDatabaseVersion(current_db_version, current_db_structure, current_db_content, description);
sLog.outErrorDb();
PrintYouNeedDatabaseVersionExpectedByCore(core_db_requirements);
}
return true;
}