0034_file_last_commits_table.py
python
sha256:f93f34a08d829b55b7324c2dacfa517618560ddfb11c09a1120f325fb6a238af
fix: migration downgrade guards and test timing budgets
Sonnet 4.6
patch
20 days ago
| 1 | """Add musehub_file_last_commits materialized table for per-file last-commit data. |
| 2 | |
| 3 | Replaces the O(N_commits × manifest_blob) walk in get_file_last_commits with a |
| 4 | single indexed SQL read. Populated at push time by the push.file_last_commits job. |
| 5 | |
| 6 | Revision ID: 0034 |
| 7 | Revises: 0033 |
| 8 | """ |
| 9 | from __future__ import annotations |
| 10 | |
| 11 | from alembic import op |
| 12 | import sqlalchemy as sa |
| 13 | |
| 14 | revision = "0034" |
| 15 | down_revision = "0033" |
| 16 | branch_labels = None |
| 17 | depends_on = None |
| 18 | |
| 19 | |
| 20 | def upgrade() -> None: |
| 21 | op.create_table( |
| 22 | "musehub_file_last_commits", |
| 23 | sa.Column("repo_id", sa.String(128), sa.ForeignKey("musehub_repos.repo_id", ondelete="CASCADE"), primary_key=True), |
| 24 | sa.Column("branch", sa.String(255), primary_key=True), |
| 25 | sa.Column("path", sa.Text, primary_key=True), |
| 26 | sa.Column("commit_id", sa.String(128), nullable=False), |
| 27 | sa.Column("commit_message", sa.Text, nullable=False, server_default=""), |
| 28 | sa.Column("commit_author", sa.String(255), nullable=False, server_default=""), |
| 29 | sa.Column("commit_timestamp", sa.DateTime(timezone=True), nullable=False), |
| 30 | sa.Column("agent_id", sa.String(128), nullable=True), |
| 31 | sa.Column("model_id", sa.String(128), nullable=True), |
| 32 | ) |
| 33 | op.create_index( |
| 34 | "ix_file_last_commits_repo_branch", |
| 35 | "musehub_file_last_commits", |
| 36 | ["repo_id", "branch"], |
| 37 | if_not_exists=True, |
| 38 | ) |
| 39 | |
| 40 | |
| 41 | def downgrade() -> None: |
| 42 | op.execute("DROP INDEX IF EXISTS ix_file_last_commits_repo_branch") |
| 43 | bind = op.get_bind() |
| 44 | if sa.inspect(bind).has_table("musehub_file_last_commits"): |
| 45 | op.drop_table("musehub_file_last_commits") |
File History
1 commit
sha256:f93f34a08d829b55b7324c2dacfa517618560ddfb11c09a1120f325fb6a238af
fix: migration downgrade guards and test timing budgets
Sonnet 4.6
patch
20 days ago