Gatherer: aggregate several sessions of one user under the account

Session key uses the OpenVPN Client ID (survives float), one usage_history
row per user per tick, summed speeds in the API, last_bytes/real_address
per account, migration 2 (active_sessions.session_id). Also throttles the
"status file missing" log and reports recovery.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ayurishchevandClaude Sonnet 5.5 committed 2026-10-07 09:38:09 +03:00
1 parent ad6995bb63
commit 7d6f44c965
11 files changed
+287 -57

No files matched your search

+5 -4
View File
@@ -151,8 +151,9 @@ def test_old_schema_is_migrated_without_data_loss(tmp_path, schema):
# Missing tables and columns are there, existing rows get the defaults
assert {"active_sessions", "users", "login_attempts"} <= table_names(db)
assert query(db, "SELECT totp_secret, is_2fa_enabled FROM users") == [(None, 0)]
assert query(db, "SELECT session_id FROM active_sessions") in ([], [(None,)]) # migration 2: column exists, NULL
# Stamped, and the backup is the untouched pre-migration copy
assert query(db, "SELECT version, name FROM schema_migrations") == [(1, "baseline")]
assert query(db, "SELECT version, name FROM schema_migrations") == [(1, "baseline"), (2, "session_id")]
backups = glob.glob(db + ".bak-*")
assert backups == [report.backup]
assert [query(backups[0], q) for q in DATA_QUERIES] == before
@@ -204,7 +205,7 @@ def test_fresh_database_gets_full_schema_without_backup(tmp_path):
assert glob.glob(db + ".bak-*") == []
assert {"clients", "usage_history", "active_sessions", "users", "login_attempts",
"stats_5min", "stats_daily", "schema_migrations"} <= table_names(db)
assert query(db, "SELECT version FROM schema_migrations") == [(1,)]
assert query(db, "SELECT version FROM schema_migrations") == [(1,), (2,)]
def test_auto_migrate_off_refuses_while_pending(tmp_path, monkeypatch):
@@ -242,5 +243,5 @@ def test_simultaneous_start_makes_one_backup(tmp_path):
assert errors == []
assert len(glob.glob(db + ".bak-*")) == 1
assert sorted(len(r.applied) for r in reports) == [0, 1]
assert query(db, "SELECT version FROM schema_migrations") == [(1,)]
assert sorted(len(r.applied) for r in reports) == [0, len(migrations.MIGRATIONS)]
assert query(db, "SELECT version FROM schema_migrations") == [(1,), (2,)]