From 1ce39c8e76bee5819d0f891bb9c292552e156687 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Mon, 10 Nov 2025 17:16:21 +0000 Subject: [PATCH] Add an option to not preserve old data in db_json. --- data/anope.example.conf | 12 ++++++++++++ modules/database/db_json.cpp | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/data/anope.example.conf b/data/anope.example.conf index 19476c039..6ddec1ec6 100644 --- a/data/anope.example.conf +++ b/data/anope.example.conf @@ -1147,8 +1147,20 @@ module * Allows Anope to continue writing the database even if the original can * not be backed up. This is not recommended as it may result in total data * loss during the circumstances described above. + * + * Defaults to no. */ #ignore_backup_failure = yes + + /* + * Whether to preserve unknown data within the database. When a module is + * unloaded its data will be kept in the database so that it continues to + * function when reloaded. You can turn this off to clean up unknown data + * on the next database write. + * + * Defaults to yes. + */ + #preserve_unknown_data = no } /* diff --git a/modules/database/db_json.cpp b/modules/database/db_json.cpp index 9fba40b84..d2aa5fe85 100644 --- a/modules/database/db_json.cpp +++ b/modules/database/db_json.cpp @@ -363,6 +363,10 @@ public: void OnSaveDatabase() override { + // Step 0: clear the old data if we don't want to preserve it. + if (!Config->GetModule(this).Get("preserve_unknown_data", "yes")) + databases.clear(); + // Step 1: clear the old data. for (const auto &type : Serialize::Type::GetTypeOrder()) {