feat: add /history switch for runtime database backend switching

Add log_database_switch_backend() that closes the current backend,
updates PREF_DBLOG preference, and reinitializes with the new backend
without requiring a reconnect or restart.

New command: /history switch sqlite|flatfile
- Validates connection state and backend name
- Skips if already using the requested backend
- Autocomplete support for the subcommand
This commit is contained in:
2026-02-26 14:04:38 +03:00
parent 1f3d3117bf
commit b5fe714a89
6 changed files with 85 additions and 0 deletions

View File

@@ -44,6 +44,7 @@
#include "config.h"
#include "database.h"
#include "config/preferences.h"
#include "config/accounts.h"
#include "ui/ui.h"
#include "xmpp/xmpp.h"
#include "xmpp/message.h"
@@ -96,6 +97,34 @@ log_database_close(void)
active_db_backend = NULL;
}
gboolean
log_database_switch_backend(const char* new_backend)
{
// Close current backend
log_database_close();
// Update preference
prefs_set_string(PREF_DBLOG, new_backend);
prefs_save();
// Get current account to reinitialize
const char* account_name = session_get_account_name();
if (!account_name) {
log_error("log_database_switch_backend: no active session");
return FALSE;
}
ProfAccount* account = accounts_get_account(account_name);
if (!account) {
log_error("log_database_switch_backend: account '%s' not found", account_name);
return FALSE;
}
gboolean result = log_database_init(account);
account_free(account);
return result;
}
void
log_database_add_incoming(ProfMessage* message)
{