0011_v2_proposals_and_intel_tables.py
python
sha256:a10adeeb7a0169cb9900f9806ed7a973047258abb6283724fe55e8eb68ff3f0a
init: musehub initial commit
Human
171 days ago
| 1 | """V2: rename pull requests to proposals, add intel/coord/health tables. |
| 2 | |
| 3 | No backwards compatibility. Hard rename musehub_pull_requests → musehub_proposals. |
| 4 | No view alias. Add V2 risk + domain columns to proposals. Rename review/comment tables. |
| 5 | Add musehub_symbol_index, musehub_health_snapshots, musehub_coord_reservations, |
| 6 | musehub_coord_tasks. |
| 7 | |
| 8 | Revision ID: 0011 |
| 9 | Revises: 0010 |
| 10 | """ |
| 11 | |
| 12 | from __future__ import annotations |
| 13 | |
| 14 | from alembic import op |
| 15 | import sqlalchemy as sa |
| 16 | |
| 17 | revision: str = "0011" |
| 18 | down_revision: str = "0010" |
| 19 | branch_labels = None |
| 20 | depends_on = None |
| 21 | |
| 22 | |
| 23 | def upgrade() -> None: |
| 24 | # ── Rename pull_requests → proposals ────────────────────────────────────── |
| 25 | op.rename_table("musehub_pull_requests", "musehub_proposals") |
| 26 | |
| 27 | # Add V2 risk + domain columns to proposals |
| 28 | op.add_column("musehub_proposals", sa.Column("domain_diff", sa.JSON(), nullable=True)) |
| 29 | op.add_column("musehub_proposals", sa.Column("risk_score", sa.Float(), nullable=True)) |
| 30 | op.add_column("musehub_proposals", sa.Column("blast_delta", sa.Float(), nullable=True)) |
| 31 | op.add_column("musehub_proposals", sa.Column("breakage_count", sa.Integer(), nullable=True, server_default="0")) |
| 32 | op.add_column("musehub_proposals", sa.Column("test_gap_count", sa.Integer(), nullable=True, server_default="0")) |
| 33 | op.add_column("musehub_proposals", sa.Column("symbols_changed", sa.Integer(), nullable=True, server_default="0")) |
| 34 | |
| 35 | # ── Rename pr_reviews → proposal_reviews ────────────────────────────────── |
| 36 | op.rename_table("musehub_pr_reviews", "musehub_proposal_reviews") |
| 37 | |
| 38 | # ── Rename pr_comments → proposal_comments ──────────────────────────────── |
| 39 | op.rename_table("musehub_pr_comments", "musehub_proposal_comments") |
| 40 | |
| 41 | # Add symbol_address to proposal_comments (V2: anchor to symbol, not line number) |
| 42 | op.add_column("musehub_proposal_comments", sa.Column("symbol_address", sa.String(512), nullable=True)) |
| 43 | |
| 44 | # ── New: musehub_symbol_index ────────────────────────────────────────────── |
| 45 | op.create_table( |
| 46 | "musehub_symbol_index", |
| 47 | sa.Column("index_id", sa.String(36), nullable=False), |
| 48 | sa.Column("repo_id", sa.String(36), nullable=False), |
| 49 | sa.Column("ref", sa.String(64), nullable=False), |
| 50 | sa.Column("symbol_history", sa.LargeBinary(), nullable=True), |
| 51 | sa.Column("hash_occurrence", sa.LargeBinary(), nullable=True), |
| 52 | sa.Column("built_at", sa.DateTime(timezone=True), nullable=False), |
| 53 | sa.ForeignKeyConstraint(["repo_id"], ["musehub_repos.repo_id"], ondelete="CASCADE"), |
| 54 | sa.PrimaryKeyConstraint("index_id"), |
| 55 | ) |
| 56 | op.create_index("ix_symbol_index_repo_id", "musehub_symbol_index", ["repo_id"]) |
| 57 | |
| 58 | # ── New: musehub_health_snapshots ────────────────────────────────────────── |
| 59 | op.create_table( |
| 60 | "musehub_health_snapshots", |
| 61 | sa.Column("snapshot_id", sa.String(36), nullable=False), |
| 62 | sa.Column("repo_id", sa.String(36), nullable=False), |
| 63 | sa.Column("ref", sa.String(64), nullable=False), |
| 64 | sa.Column("score", sa.Float(), nullable=True), |
| 65 | sa.Column("breakage_count", sa.Integer(), nullable=False, server_default="0"), |
| 66 | sa.Column("dead_code_count", sa.Integer(), nullable=False, server_default="0"), |
| 67 | sa.Column("type_coverage", sa.Float(), nullable=True), |
| 68 | sa.Column("test_gap_count", sa.Integer(), nullable=False, server_default="0"), |
| 69 | sa.Column("blast_risk_p95", sa.Float(), nullable=True), |
| 70 | sa.Column("computed_at", sa.DateTime(timezone=True), nullable=False), |
| 71 | sa.ForeignKeyConstraint(["repo_id"], ["musehub_repos.repo_id"], ondelete="CASCADE"), |
| 72 | sa.PrimaryKeyConstraint("snapshot_id"), |
| 73 | ) |
| 74 | op.create_index("ix_health_snapshots_repo_id", "musehub_health_snapshots", ["repo_id"]) |
| 75 | |
| 76 | # ── New: musehub_coord_reservations ─────────────────────────────────────── |
| 77 | op.create_table( |
| 78 | "musehub_coord_reservations", |
| 79 | sa.Column("reservation_id", sa.String(36), nullable=False), |
| 80 | sa.Column("repo_id", sa.String(36), nullable=False), |
| 81 | sa.Column("symbol_address", sa.String(512), nullable=False), |
| 82 | sa.Column("agent_id", sa.String(255), nullable=False), |
| 83 | sa.Column("agent_model_id", sa.String(255), nullable=False, server_default=""), |
| 84 | sa.Column("ttl_s", sa.Integer(), nullable=False, server_default="300"), |
| 85 | sa.Column("created_at", sa.DateTime(timezone=True), nullable=False), |
| 86 | sa.Column("expires_at", sa.DateTime(timezone=True), nullable=False), |
| 87 | sa.Column("released_at", sa.DateTime(timezone=True), nullable=True), |
| 88 | sa.ForeignKeyConstraint(["repo_id"], ["musehub_repos.repo_id"], ondelete="CASCADE"), |
| 89 | sa.PrimaryKeyConstraint("reservation_id"), |
| 90 | ) |
| 91 | op.create_index("ix_coord_reservations_repo_id", "musehub_coord_reservations", ["repo_id"]) |
| 92 | op.create_index( |
| 93 | "ix_coord_reservations_active", |
| 94 | "musehub_coord_reservations", |
| 95 | ["repo_id", "symbol_address", "released_at"], |
| 96 | ) |
| 97 | |
| 98 | # ── New: musehub_coord_tasks ─────────────────────────────────────────────── |
| 99 | op.create_table( |
| 100 | "musehub_coord_tasks", |
| 101 | sa.Column("task_id", sa.String(36), nullable=False), |
| 102 | sa.Column("repo_id", sa.String(36), nullable=False), |
| 103 | sa.Column("queue", sa.String(255), nullable=False, server_default="default"), |
| 104 | sa.Column("priority", sa.Integer(), nullable=False, server_default="50"), |
| 105 | sa.Column("payload", sa.JSON(), nullable=False), |
| 106 | sa.Column("status", sa.String(20), nullable=False, server_default="pending"), |
| 107 | sa.Column("claimed_by", sa.String(255), nullable=True), |
| 108 | sa.Column("claimed_at", sa.DateTime(timezone=True), nullable=True), |
| 109 | sa.Column("completed_at", sa.DateTime(timezone=True), nullable=True), |
| 110 | sa.Column("depends_on", sa.JSON(), nullable=False), |
| 111 | sa.Column("run_id", sa.String(255), nullable=True), |
| 112 | sa.Column("created_at", sa.DateTime(timezone=True), nullable=False), |
| 113 | sa.ForeignKeyConstraint(["repo_id"], ["musehub_repos.repo_id"], ondelete="CASCADE"), |
| 114 | sa.PrimaryKeyConstraint("task_id"), |
| 115 | ) |
| 116 | op.create_index("ix_coord_tasks_repo_queue_status", "musehub_coord_tasks", ["repo_id", "queue", "status"]) |
| 117 | op.create_index("ix_coord_tasks_repo_priority", "musehub_coord_tasks", ["repo_id", "priority"]) |
| 118 | |
| 119 | |
| 120 | def downgrade() -> None: |
| 121 | op.drop_index("ix_coord_tasks_repo_priority", table_name="musehub_coord_tasks") |
| 122 | op.drop_index("ix_coord_tasks_repo_queue_status", table_name="musehub_coord_tasks") |
| 123 | op.drop_table("musehub_coord_tasks") |
| 124 | |
| 125 | op.drop_index("ix_coord_reservations_active", table_name="musehub_coord_reservations") |
| 126 | op.drop_index("ix_coord_reservations_repo_id", table_name="musehub_coord_reservations") |
| 127 | op.drop_table("musehub_coord_reservations") |
| 128 | |
| 129 | op.drop_index("ix_health_snapshots_repo_id", table_name="musehub_health_snapshots") |
| 130 | op.drop_table("musehub_health_snapshots") |
| 131 | |
| 132 | op.drop_index("ix_symbol_index_repo_id", table_name="musehub_symbol_index") |
| 133 | op.drop_table("musehub_symbol_index") |
| 134 | |
| 135 | op.drop_column("musehub_proposal_comments", "symbol_address") |
| 136 | op.rename_table("musehub_proposal_comments", "musehub_pr_comments") |
| 137 | op.rename_table("musehub_proposal_reviews", "musehub_pr_reviews") |
| 138 | |
| 139 | op.drop_column("musehub_proposals", "symbols_changed") |
| 140 | op.drop_column("musehub_proposals", "test_gap_count") |
| 141 | op.drop_column("musehub_proposals", "breakage_count") |
| 142 | op.drop_column("musehub_proposals", "blast_delta") |
| 143 | op.drop_column("musehub_proposals", "risk_score") |
| 144 | op.drop_column("musehub_proposals", "domain_diff") |
| 145 | op.rename_table("musehub_proposals", "musehub_pull_requests") |
File History
1 commit
sha256:a10adeeb7a0169cb9900f9806ed7a973047258abb6283724fe55e8eb68ff3f0a
init: musehub initial commit
Human
171 days ago