feat(draft): add /history export|import for SQLite<->flatfile migration
All checks were successful
CI Code / Check spelling (pull_request) Successful in 18s
CI Code / Check coding style (pull_request) Successful in 31s
CI Code / Code Coverage (pull_request) Successful in 4m48s
CI Code / Linux (debian) (pull_request) Successful in 6m11s
CI Code / Linux (ubuntu) (pull_request) Successful in 6m16s
CI Code / Linux (arch) (pull_request) Successful in 6m28s
All checks were successful
CI Code / Check spelling (pull_request) Successful in 18s
CI Code / Check coding style (pull_request) Successful in 31s
CI Code / Code Coverage (pull_request) Successful in 4m48s
CI Code / Linux (debian) (pull_request) Successful in 6m11s
CI Code / Linux (ubuntu) (pull_request) Successful in 6m16s
CI Code / Linux (arch) (pull_request) Successful in 6m28s
DRAFT — not yet tested end-to-end with a live XMPP session. New commands: /history export [<jid>] — copy messages from SQLite to flat-file /history import [<jid>] — copy messages from flat-file to SQLite Both merge with existing data; duplicates are skipped using stanza-id or a SHA-256 fallback key (timestamp + sender + body prefix). Implementation (src/database_export.c): - Export: paginate SQLite via get_previous_chat, read existing flatfile for dedup, write merged result via ff_write_line + atomic rename - Import: parse flatfile lines via ff_parse_line, build dedup set from SQLite, insert new messages via add_incoming (preserves original timestamps for both directions) - List all contacts: db_sqlite_list_contacts() queries UNION of DISTINCT from_jid/to_jid; flatfile enumerates flatlog directories Wiring: - database.h: declare export/import functions + db_sqlite_list_contacts - database_sqlite.c: add db_sqlite_list_contacts() - cmd_defs.c: add export/import to /history synopsis and args - cmd_funcs.c: add export/import handlers in cmd_history() - cmd_ac.c: add 'export' and 'import' to history_ac - Makefile.am: add database_export.c to core_sources - stub_database.c: add stubs for test linking - profanity.1: document export/import in man page All code guarded with #ifdef HAVE_SQLITE — builds cleanly without it.
This commit is contained in:
@@ -6787,6 +6787,42 @@ cmd_history(ProfWin* window, const char* const command, gchar** args)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[0], "export") == 0) {
|
||||
#ifdef HAVE_SQLITE
|
||||
const gchar* contact_jid = args[1]; // may be NULL (export all)
|
||||
if (contact_jid) {
|
||||
cons_show("Exporting SQLite history for %s to flat-file...", contact_jid);
|
||||
} else {
|
||||
cons_show("Exporting all SQLite history to flat-file...");
|
||||
}
|
||||
int n = log_database_export_to_flatfile(contact_jid);
|
||||
if (n >= 0) {
|
||||
cons_show("Export complete: %d message(s) exported.", n);
|
||||
}
|
||||
#else
|
||||
cons_show_error("Export requires SQLite support. Rebuild with --with-sqlite.");
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (g_strcmp0(args[0], "import") == 0) {
|
||||
#ifdef HAVE_SQLITE
|
||||
const gchar* contact_jid = args[1]; // may be NULL (import all)
|
||||
if (contact_jid) {
|
||||
cons_show("Importing flat-file history for %s into SQLite...", contact_jid);
|
||||
} else {
|
||||
cons_show("Importing all flat-file history into SQLite...");
|
||||
}
|
||||
int n = log_database_import_from_flatfile(contact_jid);
|
||||
if (n >= 0) {
|
||||
cons_show("Import complete: %d message(s) imported.", n);
|
||||
}
|
||||
#else
|
||||
cons_show_error("Import requires SQLite support. Rebuild with --with-sqlite.");
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
_cmd_set_boolean_preference(args[0], "Chat history", PREF_HISTORY);
|
||||
|
||||
// if set to on, set chlog (/logging chat on)
|
||||
|
||||
Reference in New Issue
Block a user