gabriel / musehub public
0057_branch_repo_name_index.py python
39 lines 1.2 KB
Raw
sha256:20b27796ed512236119feef48b4577a8fd9ded05a15267dd4e6da23604ad1f1a docs: update Suggested Ownership Split table to reflect ful… Sonnet 5 32 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 3 commits
sha256:20b27796ed512236119feef48b4577a8fd9ded05a15267dd4e6da23604ad1f1a docs: update Suggested Ownership Split table to reflect ful… Sonnet 5 32 days ago
sha256:8ea2f75226d5834770ccaddbaa6efda1cc337446fd481bb385de8bec4555ae79 docs: Section 9 CI pipeline — confirm job queue is idempote… Sonnet 5 32 days ago
sha256:80e1a60a39562f6e616aaafbb27487f03abbec7d8ffc6164302b7a0c0bfc63ee docs: check off Section 0 items verified in inventory doc, … Sonnet 5 32 days ago