def upgrade() -> None:
    """Add performance indexes to entity table."""
    # Create index on sync_id for faster filtering
    op.create_index(
        'idx_entity_sync_id',
        'entity',
        ['sync_id'],
        unique=False,
        postgresql_using='btree'
    )

    # Create index on sync_job_id for job-based queries
    op.create_index(
        'idx_entity_sync_job_id',
        'entity',
        ['sync_job_id'],
        unique=False,
        postgresql_using='btree'
    )

    # Create index on entity_id for lookups
    op.create_index(
        'idx_entity_entity_id',
        'entity',
        ['entity_id'],
        unique=False,
        postgresql_using='btree'
    )

    # Create composite index for the most common query pattern
    # This is used by get_by_entity_and_sync_id
    op.create_index(
        'idx_entity_entity_id_sync_id',
        'entity',
        ['entity_id', 'sync_id'],
        unique=False,
        postgresql_using='btree'
    )
Add performance indexes to entity table.
backend/alembic/versions/add_entity_performance_indexes.py