gabriel / musehub public
0057_branch_repo_name_index.py python
39 lines 1.2 KB
Raw
sha256:c73281cffffbc70487969720af074e54b34326d59ec6aff0827fa16512a4e512 docs(mwp-2): mark all acceptance criteria met; add closing … Sonnet 4.6 81 days ago
1 """Add composite (repo_id, name) index on musehub_branches.
2
3 get_branch_head_commit_id() does a point lookup WHERE repo_id = ? AND name = ?
4 on every push and fetch. Without a composite index this scans all branches for
5 the repo. list_branches_with_detail() also benefits: the composite index covers
6 both the WHERE clause and the ORDER BY name, eliminating an in-memory sort.
7
8 Revision ID: 0057
9 Revises: 0056
10 """
11 from __future__ import annotations
12
13 from alembic import op
14
15 revision = "0057"
16 down_revision = "0056"
17 branch_labels = None
18 depends_on = None
19
20
21 def upgrade() -> None:
22 op.create_index(
23 "ix_musehub_branches_repo_name",
24 "musehub_branches",
25 ["repo_id", "name"],
26 )
27 # The composite index on (repo_id, name) makes the single-column repo_id
28 # index redundant — PostgreSQL can satisfy any repo_id-only scan using the
29 # leftmost prefix of the composite index.
30 op.drop_index("ix_musehub_branches_repo_id", table_name="musehub_branches")
31
32
33 def downgrade() -> None:
34 op.create_index(
35 "ix_musehub_branches_repo_id",
36 "musehub_branches",
37 ["repo_id"],
38 )
39 op.drop_index("ix_musehub_branches_repo_name", table_name="musehub_branches")
File History 2 commits
sha256:c73281cffffbc70487969720af074e54b34326d59ec6aff0827fa16512a4e512 docs(mwp-2): mark all acceptance criteria met; add closing … Sonnet 4.6 81 days ago
sha256:4dd2a937f66f8e36d9aa59bd1bf3cb880ca1d503fef67300a0cba3b482784081 test(mwp2): Phase 0 RED — reproduction tests for _walk_comm… Sonnet 4.6 81 days ago