0057_branch_repo_name_index.py
python
sha256:969ddc5e88776e70af33c016b8777bb721356508ae5f304b3fb46c451494ece7
test(mwp3): Phase 4 — fix adjacent suite regressions, lock …
Sonnet 4.6
22 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:969ddc5e88776e70af33c016b8777bb721356508ae5f304b3fb46c451494ece7
test(mwp3): Phase 4 — fix adjacent suite regressions, lock …
Sonnet 4.6
22 days ago
sha256:1749b9cc5cd2583c56d3261c4c00a342c27435f3946d4bc3e70f76aa2795458a
docs(mwp-3): TDD implementation plan for job-enqueue idempo…
Opus 4.8
22 days ago