Files
saas_backend/alembic/versions/e7b2d5c9a14f_audit_retention_index.py
T
2026-08-31 20:39:41 -04:00

34 lines
1.1 KiB
Python

"""An index the retention sweep can actually use.
`ix_audit_logs_...` on `(tenant_id, created_at)` serves the operations views,
which always ask about one workspace. Retention asks the opposite question — the
oldest rows *across every workspace*, split by whether the module is one of the
security ones — and that index cannot help with it.
At a few thousand rows nothing notices. The sweep exists precisely for the table
that has grown for two years, which is where a sequential scan per batch, twenty
batches a night, becomes the reason the nightly job never finishes.
Revision ID: e7b2d5c9a14f
Revises: d4a7c2f8b51e
"""
from typing import Sequence, Union
from alembic import op
revision: str = "e7b2d5c9a14f"
down_revision: Union[str, Sequence[str], None] = "d4a7c2f8b51e"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_index(
"ix_audit_logs_module_created", "audit_logs", ["module_name", "created_at"]
)
def downgrade() -> None:
op.drop_index("ix_audit_logs_module_created", table_name="audit_logs")