f39467ec08
对齐前端首页可见事件home_visible --------- Co-authored-by: guke <guke@autohome.com.cn> Reviewed-on: #151
39 lines
1.6 KiB
Python
39 lines
1.6 KiB
Python
"""analytics_event 活跃口径复合索引
|
||
|
||
Revision ID: analytics_active_idx
|
||
Revises: 135e79414fd0
|
||
Create Date: 2026-07-18 17:35:00.000000
|
||
|
||
给 analytics_event 加活跃口径热点复合索引 (event, page, user_id, created_at):
|
||
activity.active_event_condition 按 event IN (home_visible ∪ 比价 ∪ 领券) 过滤后
|
||
group by user_id、max(created_at)。覆盖索引让该聚合走 index-only,避免高频活跃事件全表扫。
|
||
(历史:早期首页可见用 event=show+page=home 组合,故索引含 page 列;现改单一 home_visible、
|
||
不再按 page 过滤 → page 列成冗余,索引仍靠 event 前缀生效;如需更优可后续新迁移瘦成 (event,user_id,created_at)。)
|
||
|
||
⚠️ 本分支迁移树有**既有多头**:135e79414fd0(不活跃两表)与 phone_rebind_log 同从
|
||
comparison_llm_cost 分叉,`alembic upgrade head` 会多头报错。本迁移挂在 135e79414fd0
|
||
一侧;集成到 main 时需 `alembic merge` 合并 phone_rebind_log 那个头(与本迁移无关的既有问题)。
|
||
"""
|
||
from typing import Sequence, Union
|
||
|
||
from alembic import op
|
||
|
||
# revision identifiers, used by Alembic.
|
||
revision: str = "analytics_active_idx"
|
||
down_revision: Union[str, Sequence[str], None] = "135e79414fd0"
|
||
branch_labels: Union[str, Sequence[str], None] = None
|
||
depends_on: Union[str, Sequence[str], None] = None
|
||
|
||
|
||
def upgrade() -> None:
|
||
op.create_index(
|
||
"ix_analytics_event_active",
|
||
"analytics_event",
|
||
["event", "page", "user_id", "created_at"],
|
||
unique=False,
|
||
)
|
||
|
||
|
||
def downgrade() -> None:
|
||
op.drop_index("ix_analytics_event_active", table_name="analytics_event")
|