0031_symbol_vitals_coupling_history_cols.py
python
sha256:009b5a222314f47640a58d75ce5a1f428f1624cf0b51384dfcdfbdfab3cc42a4
feat: migration idempotency, file attribution DAG walk, mpa…
Sonnet 4.6
minor
⚠ breaking
7 days ago
| 1 | """Add symbol vitals + coupling tables; add message/commit_branch to history entries. |
| 2 | |
| 3 | Pre-computes coupling and symbol vitals at push time so the symbol detail |
| 4 | page is a set of simple indexed reads instead of expensive aggregations. |
| 5 | |
| 6 | New tables: |
| 7 | musehub_symbol_vitals — first_introduced, change_count, version_count, op breakdown |
| 8 | musehub_symbol_coupling — (address, co_address, shared_commits) |
| 9 | |
| 10 | New columns on musehub_symbol_history_entries: |
| 11 | message — commit message (denormalized from musehub_commits) |
| 12 | commit_branch — branch the commit landed on |
| 13 | |
| 14 | Revision ID: 0031 |
| 15 | Revises: 0030 |
| 16 | """ |
| 17 | from __future__ import annotations |
| 18 | |
| 19 | from alembic import op |
| 20 | import sqlalchemy as sa |
| 21 | |
| 22 | revision = "0031" |
| 23 | down_revision = "0030" |
| 24 | branch_labels = None |
| 25 | depends_on = None |
| 26 | |
| 27 | |
| 28 | def upgrade() -> None: |
| 29 | op.add_column( |
| 30 | "musehub_symbol_history_entries", |
| 31 | sa.Column("message", sa.Text, nullable=True), |
| 32 | ) |
| 33 | op.add_column( |
| 34 | "musehub_symbol_history_entries", |
| 35 | sa.Column("commit_branch", sa.String(512), nullable=True), |
| 36 | ) |
| 37 | |
| 38 | op.create_table( |
| 39 | "musehub_symbol_vitals", |
| 40 | sa.Column("repo_id", sa.String(128), sa.ForeignKey("musehub_repos.repo_id", ondelete="CASCADE"), primary_key=True, nullable=False), |
| 41 | sa.Column("address", sa.String(512), primary_key=True, nullable=False), |
| 42 | sa.Column("first_introduced", sa.DateTime(timezone=True), nullable=True), |
| 43 | sa.Column("change_count", sa.Integer, nullable=False, server_default="0"), |
| 44 | sa.Column("version_count", sa.Integer, nullable=False, server_default="0"), |
| 45 | sa.Column("op_add", sa.Integer, nullable=False, server_default="0"), |
| 46 | sa.Column("op_modify", sa.Integer, nullable=False, server_default="0"), |
| 47 | sa.Column("op_delete", sa.Integer, nullable=False, server_default="0"), |
| 48 | sa.Column("op_move", sa.Integer, nullable=False, server_default="0"), |
| 49 | ) |
| 50 | op.create_index("ix_symbol_vitals_repo", "musehub_symbol_vitals", ["repo_id"]) |
| 51 | |
| 52 | op.create_table( |
| 53 | "musehub_symbol_coupling", |
| 54 | sa.Column("repo_id", sa.String(128), sa.ForeignKey("musehub_repos.repo_id", ondelete="CASCADE"), primary_key=True, nullable=False), |
| 55 | sa.Column("address", sa.String(512), primary_key=True, nullable=False), |
| 56 | sa.Column("co_address", sa.String(512), primary_key=True, nullable=False), |
| 57 | sa.Column("shared_commits", sa.Integer, nullable=False, server_default="0"), |
| 58 | ) |
| 59 | op.create_index("ix_symbol_coupling_repo_address", "musehub_symbol_coupling", ["repo_id", "address"]) |
| 60 | |
| 61 | |
| 62 | def downgrade() -> None: |
| 63 | from sqlalchemy import text |
| 64 | op.execute(text("DROP INDEX IF EXISTS ix_symbol_coupling_repo_address")) |
| 65 | op.execute(text("DROP TABLE IF EXISTS musehub_symbol_coupling")) |
| 66 | op.execute(text("DROP INDEX IF EXISTS ix_symbol_vitals_repo")) |
| 67 | op.execute(text("DROP TABLE IF EXISTS musehub_symbol_vitals")) |
| 68 | op.execute(text("ALTER TABLE musehub_symbol_history_entries DROP COLUMN IF EXISTS commit_branch")) |
| 69 | op.execute(text("ALTER TABLE musehub_symbol_history_entries DROP COLUMN IF EXISTS message")) |
File History
1 commit
sha256:009b5a222314f47640a58d75ce5a1f428f1624cf0b51384dfcdfbdfab3cc42a4
feat: migration idempotency, file attribution DAG walk, mpa…
Sonnet 4.6
minor
⚠
7 days ago