From aeb51b9ccc534cc1aba9b758dac7fbe3b3c83cb5 Mon Sep 17 00:00:00 2001 From: 3252a8 <3252a8@proton.me> Date: Fri, 15 May 2026 23:57:39 +0300 Subject: [PATCH] refactor: add indexes on payments(status, created_at) and message_logs(timestamp) --- db/migrator.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/db/migrator.py b/db/migrator.py index f721d60..cc7c926 100644 --- a/db/migrator.py +++ b/db/migrator.py @@ -729,6 +729,21 @@ def _migration_0017_reconcile_legacy_admin_api_schema(connection: Connection) -> ) +def _migration_0022_add_indexes_for_admin_reports(connection: Connection) -> None: + connection.execute( + text( + "CREATE INDEX IF NOT EXISTS ix_payments_status_created_at " + "ON payments (status, created_at)" + ) + ) + connection.execute( + text( + "CREATE INDEX IF NOT EXISTS ix_message_logs_timestamp " + "ON message_logs (timestamp DESC)" + ) + ) + + MIGRATIONS: List[Migration] = [ Migration( id="0001_add_channel_subscription_fields", @@ -846,6 +861,11 @@ MIGRATIONS: List[Migration] = [ description="Admin toggle for effectively unlimited main traffic limit", upgrade=_migration_0021_add_regular_unlimited_override, ), + Migration( + id="0022_add_indexes_for_admin_reports", + description="Indexes to speed up financial stats and admin log queries", + upgrade=_migration_0022_add_indexes_for_admin_reports, + ), ]