mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/DBUpdater: Add the possibility to limit the remove of orphaned entries.
* This will save you from loosing your update history if you use a repository in bad state (revision or branch) by mistake. * Also turned 1 error message into a warning
This commit is contained in:
@@ -234,13 +234,16 @@ Updates.ArchivedRedundancy = 0
|
||||
Updates.AllowRehash = 1
|
||||
|
||||
#
|
||||
# Updates.CleanDeadRef
|
||||
# Description: Cleans dead/ orphaned references that occure if a update was deleted or renamed and edited.
|
||||
# Updates.CleanDeadRefMaxCount
|
||||
# Description: Cleans dead/ orphaned references that occur if an update was removed or renamed and edited in one step.
|
||||
# It only starts the clean up if the count of the missing updates is below or equal the Updates.CleanDeadRefMaxCount value.
|
||||
# This way prevents erasing of the update history due to wrong source directory state (maybe wrong branch or bad revision).
|
||||
# Disable this if you want to know if the database is in a possible "dirty state".
|
||||
# Default: 1 - (Enabled)
|
||||
# Default: 3 - (Enabled)
|
||||
# 0 - (Disabled)
|
||||
# -1 - (Enabled - unlimited)
|
||||
|
||||
Updates.CleanDeadRef = 1
|
||||
Updates.CleanDeadRefMaxCount = 3
|
||||
|
||||
#
|
||||
###################################################################################################
|
||||
|
||||
@@ -276,7 +276,7 @@ bool DBUpdater<T>::Update(DatabaseWorkerPool<T>& pool)
|
||||
sConfigMgr->GetBoolDefault("Updates.Redundancy", true),
|
||||
sConfigMgr->GetBoolDefault("Updates.AllowRehash", true),
|
||||
sConfigMgr->GetBoolDefault("Updates.ArchivedRedundancy", false),
|
||||
sConfigMgr->GetBoolDefault("Updates.CleanDeadRef", true));
|
||||
sConfigMgr->GetIntDefault("Updates.CleanDeadRefMaxCount", 3));
|
||||
|
||||
if (!count)
|
||||
TC_LOG_INFO("sql.updates", ">> %s database is up-to-date!", DBUpdater<T>::GetTableName().c_str());
|
||||
|
||||
@@ -101,7 +101,7 @@ UpdateFetcher::DirectoryStorage UpdateFetcher::ReceiveIncludedDirectories() cons
|
||||
|
||||
if (!is_directory(p))
|
||||
{
|
||||
TC_LOG_ERROR("sql.updates", "DBUpdater: Given update include directory \"%s\" isn't existing, skipped!", p.generic_string().c_str());
|
||||
TC_LOG_WARN("sql.updates", "DBUpdater: Given update include directory \"%s\" isn't existing, skipped!", p.generic_string().c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ UpdateFetcher::SQLUpdate UpdateFetcher::ReadSQLUpdate(boost::filesystem::path co
|
||||
return update;
|
||||
}
|
||||
|
||||
uint32 UpdateFetcher::Update(bool const redundancyChecks, bool const allowRehash, bool const archivedRedundancy, bool const cleanDeadReferences) const
|
||||
uint32 UpdateFetcher::Update(bool const redundancyChecks, bool const allowRehash, bool const archivedRedundancy, int32 const cleanDeadReferencesMaxCount) const
|
||||
{
|
||||
LocaleFileStorage const available = GetFileList();
|
||||
AppliedFileStorage applied = ReceiveAppliedFiles();
|
||||
@@ -291,14 +291,28 @@ uint32 UpdateFetcher::Update(bool const redundancyChecks, bool const allowRehash
|
||||
++importedUpdates;
|
||||
}
|
||||
|
||||
for (auto const& entry : applied)
|
||||
// Cleanup up orphaned entries if enabled
|
||||
if (!applied.empty())
|
||||
{
|
||||
TC_LOG_WARN("sql.updates", ">> File \'%s\' was applied to the database but is missing in" \
|
||||
" your update directory now!%s", entry.first.c_str(), cleanDeadReferences ? " Deleting orphaned entry..." : "");
|
||||
}
|
||||
bool const doCleanup = (cleanDeadReferencesMaxCount == -1) || (applied.size() <= cleanDeadReferencesMaxCount);
|
||||
|
||||
if (cleanDeadReferences)
|
||||
CleanUp(applied);
|
||||
for (auto const& entry : applied)
|
||||
{
|
||||
TC_LOG_WARN("sql.updates", ">> File \'%s\' was applied to the database but is missing in" \
|
||||
" your update directory now!", entry.first.c_str());
|
||||
|
||||
if (doCleanup)
|
||||
TC_LOG_INFO("sql.updates", "Deleting orphaned entry \'%s\'...", entry.first.c_str());
|
||||
}
|
||||
|
||||
if (doCleanup)
|
||||
CleanUp(applied);
|
||||
else
|
||||
{
|
||||
TC_LOG_ERROR("sql.updates", "Cleanup is disabled! There are %u dirty files that were applied to your database " \
|
||||
"but are now missing in your source directory!", applied.size());
|
||||
}
|
||||
}
|
||||
|
||||
return importedUpdates;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
std::function<QueryResult(std::string const&)> const& retrieve);
|
||||
|
||||
uint32 Update(bool const redundancyChecks, bool const allowRehash,
|
||||
bool const archivedRedundancy, bool const cleanDeadReferences) const;
|
||||
bool const archivedRedundancy, int32 const cleanDeadReferencesMaxCount) const;
|
||||
|
||||
private:
|
||||
enum UpdateMode
|
||||
|
||||
@@ -1203,13 +1203,16 @@ Updates.ArchivedRedundancy = 0
|
||||
Updates.AllowRehash = 1
|
||||
|
||||
#
|
||||
# Updates.CleanDeadRef
|
||||
# Description: Cleans dead/ orphaned references that occure if a update was deleted or renamed and edited.
|
||||
# Updates.CleanDeadRefMaxCount
|
||||
# Description: Cleans dead/ orphaned references that occur if an update was removed or renamed and edited in one step.
|
||||
# It only starts the clean up if the count of the missing updates is below or equal the Updates.CleanDeadRefMaxCount value.
|
||||
# This way prevents erasing of the update history due to wrong source directory state (maybe wrong branch or bad revision).
|
||||
# Disable this if you want to know if the database is in a possible "dirty state".
|
||||
# Default: 1 - (Enabled)
|
||||
# Default: 3 - (Enabled)
|
||||
# 0 - (Disabled)
|
||||
# -1 - (Enabled - unlimited)
|
||||
|
||||
Updates.CleanDeadRef = 1
|
||||
Updates.CleanDeadRefMaxCount = 3
|
||||
|
||||
#
|
||||
###################################################################################################
|
||||
|
||||
Reference in New Issue
Block a user