"""gravity_columns Extends musehub_symbol_intel with 6 new columns that power /intel/gravity: gravity_pct FLOAT — gravity_pct from muse code gravity gravity_direct INTEGER — direct_dependents count gravity_transitive INTEGER — transitive_dependents count gravity_max_depth SMALLINT — deepest dependency chain gravity_depth_dist JSONB — {depth_level: count} for the sparkline symbol_kind VARCHAR(64) — method/function/class/async_method New index: ix_symbol_intel_repo_gravity_pct on (repo_id, gravity_pct DESC) — primary sort key for the /intel/gravity page query. Revision ID: 0005 Revises: 0004 Create Date: 2026-05-03 00:00:00.000000+00:00 """ from __future__ import annotations from typing import Sequence, Union import sqlalchemy as sa from alembic import op revision: str = '0005' down_revision: Union[str, None] = '0004' branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: op.add_column('musehub_symbol_intel', sa.Column('gravity_pct', sa.Float, nullable=True)) op.add_column('musehub_symbol_intel', sa.Column('gravity_direct', sa.Integer, nullable=True)) op.add_column('musehub_symbol_intel', sa.Column('gravity_transitive', sa.Integer, nullable=True)) op.add_column('musehub_symbol_intel', sa.Column('gravity_max_depth', sa.SmallInteger, nullable=True)) op.add_column('musehub_symbol_intel', sa.Column('gravity_depth_dist', sa.JSON, nullable=True)) op.add_column('musehub_symbol_intel', sa.Column('symbol_kind', sa.String(64), nullable=True)) op.create_index( 'ix_symbol_intel_repo_gravity_pct', 'musehub_symbol_intel', ['repo_id', sa.text('gravity_pct DESC NULLS LAST')], ) def downgrade() -> None: op.drop_index('ix_symbol_intel_repo_gravity_pct', table_name='musehub_symbol_intel') op.drop_column('musehub_symbol_intel', 'symbol_kind') op.drop_column('musehub_symbol_intel', 'gravity_depth_dist') op.drop_column('musehub_symbol_intel', 'gravity_max_depth') op.drop_column('musehub_symbol_intel', 'gravity_transitive') op.drop_column('musehub_symbol_intel', 'gravity_direct') op.drop_column('musehub_symbol_intel', 'gravity_pct')