feat(douyu): 增加账号平台七天趋势统计

This commit is contained in:
yml
2026-11-21 23:00:32 +08:00
parent 1598fa353f
commit 3e618c1a88
9 changed files with 484 additions and 4 deletions
@@ -0,0 +1,51 @@
"""add started-at index for account sync trend aggregation
The platform status panel aggregates the last seven days across all sync domains.
The existing indexes start with domain/status, so they cannot serve that range
efficiently when no domain filter is present.
"""
from __future__ import annotations
import sqlalchemy as sa
from alembic import op
revision: str = "20261121_0112"
down_revision: str | None = "20261121_0111"
branch_labels: str | None = None
depends_on: str | None = None
INDEX_NAME = "ix_account_sync_runs_started_domain_status"
def _index_exists() -> bool:
return bool(
op.get_bind()
.execute(
sa.text(
"""
SELECT COUNT(*)
FROM information_schema.statistics
WHERE table_schema = DATABASE()
AND table_name = 'account_sync_runs'
AND index_name = :index_name
"""
),
{"index_name": INDEX_NAME},
)
.scalar()
)
def upgrade() -> None:
if not _index_exists():
op.create_index(
INDEX_NAME,
"account_sync_runs",
["started_at", "domain", "status"],
)
def downgrade() -> None:
if _index_exists():
op.drop_index(INDEX_NAME, table_name="account_sync_runs")