0060_commit_graph.py
python
sha256:7d6dd8f4a89e2d1fef2d84f6e65feaff51385d382f466766b7f690a22ec18e32
fix: fall back to DB ancestry check when mpack-only fast-fo…
Sonnet 4.6
patch
6 days ago
| 1 | """Add musehub_commit_graph — precomputed reachability for O(frontier) DAG walks. |
| 2 | |
| 3 | Issue #63 Phase 2: commit graph enables _walk_commit_delta to query in bulk |
| 4 | per BFS frontier instead of one DB call per commit. |
| 5 | """ |
| 6 | |
| 7 | from __future__ import annotations |
| 8 | |
| 9 | import sqlalchemy as sa |
| 10 | from alembic import op |
| 11 | |
| 12 | revision = "0060" |
| 13 | down_revision = "0059" |
| 14 | branch_labels = None |
| 15 | depends_on = None |
| 16 | |
| 17 | |
| 18 | def upgrade() -> None: |
| 19 | op.create_table( |
| 20 | "musehub_commit_graph", |
| 21 | sa.Column("repo_id", sa.String(128), nullable=False), |
| 22 | sa.Column("commit_id", sa.String(128), nullable=False), |
| 23 | sa.Column( |
| 24 | "parent_ids", |
| 25 | sa.ARRAY(sa.Text), |
| 26 | nullable=False, |
| 27 | server_default="{}", |
| 28 | ), |
| 29 | sa.Column("generation", sa.BigInteger, nullable=False, server_default="0"), |
| 30 | sa.Column("snapshot_id", sa.String(128), nullable=True), |
| 31 | sa.Column( |
| 32 | "created_at", |
| 33 | sa.DateTime(timezone=True), |
| 34 | nullable=False, |
| 35 | server_default=sa.text("now()"), |
| 36 | ), |
| 37 | sa.ForeignKeyConstraint( |
| 38 | ["repo_id"], |
| 39 | ["musehub_repos.repo_id"], |
| 40 | ondelete="CASCADE", |
| 41 | ), |
| 42 | sa.PrimaryKeyConstraint("repo_id", "commit_id"), |
| 43 | ) |
| 44 | op.create_index( |
| 45 | "ix_musehub_commit_graph_repo_generation", |
| 46 | "musehub_commit_graph", |
| 47 | ["repo_id", "generation"], |
| 48 | ) |
| 49 | |
| 50 | |
| 51 | def downgrade() -> None: |
| 52 | op.drop_index("ix_musehub_commit_graph_repo_generation", table_name="musehub_commit_graph") |
| 53 | op.drop_table("musehub_commit_graph") |
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