gabriel / musehub public
0044_proposal_list_query_indexes.py python
56 lines 1.9 KB
Raw
sha256:7d6dd8f4a89e2d1fef2d84f6e65feaff51385d382f466766b7f690a22ec18e32 fix: fall back to DB ancestry check when mpack-only fast-fo… Sonnet 4.6 patch 6 days ago
1 """Composite indexes for proposal list query patterns (issue #35 Phase 7)
2
3 Revision ID: 0044
4 Revises: 0043
5
6 Note: CONCURRENTLY indexes cannot run inside a transaction block.
7 Uses op.get_context().autocommit_block() (Alembic 1.1+) to run each
8 DDL statement outside the implicit transaction Alembic opens.
9 """
10 from __future__ import annotations
11
12 from alembic import op
13 from sqlalchemy import text
14
15 revision: str = "0044"
16 down_revision: str = "0043"
17 branch_labels = None
18 depends_on = None
19
20 _IDX_PROPOSAL_STATE_CREATED = "ix_musehub_proposals_repo_state_created"
21 _IDX_PROPOSAL_STATE_RISK = "ix_musehub_proposals_repo_state_risk"
22 _IDX_REVIEW_PROPOSAL_STATE = "ix_musehub_proposal_reviews_proposal_state"
23 _IDX_IDENTITY_HANDLE_TYPE = "ix_musehub_identities_handle_type"
24
25 _CREATE = [
26 f"CREATE INDEX CONCURRENTLY IF NOT EXISTS {_IDX_PROPOSAL_STATE_CREATED}"
27 f" ON musehub_proposals (repo_id, state, created_at DESC)",
28
29 f"CREATE INDEX CONCURRENTLY IF NOT EXISTS {_IDX_PROPOSAL_STATE_RISK}"
30 f" ON musehub_proposals (repo_id, state, risk_score DESC NULLS LAST)",
31
32 f"CREATE INDEX CONCURRENTLY IF NOT EXISTS {_IDX_REVIEW_PROPOSAL_STATE}"
33 f" ON musehub_proposal_reviews (proposal_id, state)",
34
35 f"CREATE INDEX CONCURRENTLY IF NOT EXISTS {_IDX_IDENTITY_HANDLE_TYPE}"
36 f" ON musehub_identities (handle, identity_type)",
37 ]
38
39 _DROP = [
40 f"DROP INDEX CONCURRENTLY IF EXISTS {_IDX_PROPOSAL_STATE_CREATED}",
41 f"DROP INDEX CONCURRENTLY IF EXISTS {_IDX_PROPOSAL_STATE_RISK}",
42 f"DROP INDEX CONCURRENTLY IF EXISTS {_IDX_REVIEW_PROPOSAL_STATE}",
43 f"DROP INDEX CONCURRENTLY IF EXISTS {_IDX_IDENTITY_HANDLE_TYPE}",
44 ]
45
46
47 def upgrade() -> None:
48 with op.get_context().autocommit_block():
49 for stmt in _CREATE:
50 op.execute(text(stmt))
51
52
53 def downgrade() -> None:
54 with op.get_context().autocommit_block():
55 for stmt in _DROP:
56 op.execute(text(stmt))
File History 1 commit
sha256:7d6dd8f4a89e2d1fef2d84f6e65feaff51385d382f466766b7f690a22ec18e32 fix: fall back to DB ancestry check when mpack-only fast-fo… Sonnet 4.6 patch 6 days ago