0003_normalized_symbol_intel_tables.py
python
sha256:73f24973678ceefd56628ee17c6d0535d86e33533828af6c63348f50941515ad
Merge branch 'fix/smoke-test-tag-label' into dev
Human
15 days ago
| 1 | """normalized_symbol_intel_tables |
| 2 | |
| 3 | Replaces three unbounded JSON blobs in musehub_intel_results with normalized |
| 4 | relational tables: |
| 5 | |
| 6 | musehub_symbol_history_entries — one row per (repo_id, address, commit_id) |
| 7 | musehub_symbol_intel — one row per (repo_id, address) |
| 8 | musehub_hash_occurrence_entries — one row per (content_id, repo_id, address) |
| 9 | |
| 10 | code.symbol_history, code.per_symbol_intel, and code.hash_occurrence rows in |
| 11 | musehub_intel_results are deleted on upgrade — they will be rebuilt |
| 12 | incrementally on the next push to each repo. |
| 13 | |
| 14 | Revision ID: 0003 |
| 15 | Revises: 0002 |
| 16 | Create Date: 2026-04-29 20:45:00.000000+00:00 |
| 17 | """ |
| 18 | from __future__ import annotations |
| 19 | |
| 20 | from typing import Sequence, Union |
| 21 | |
| 22 | import sqlalchemy as sa |
| 23 | from alembic import op |
| 24 | |
| 25 | revision: str = '0003' |
| 26 | down_revision: Union[str, None] = '0002' |
| 27 | branch_labels: Union[str, Sequence[str], None] = None |
| 28 | depends_on: Union[str, Sequence[str], None] = None |
| 29 | |
| 30 | |
| 31 | def upgrade() -> None: |
| 32 | op.create_table( |
| 33 | 'musehub_symbol_history_entries', |
| 34 | sa.Column('repo_id', sa.String(128), sa.ForeignKey('musehub_repos.repo_id', ondelete='CASCADE'), primary_key=True, nullable=False), |
| 35 | sa.Column('address', sa.String(512), primary_key=True, nullable=False), |
| 36 | sa.Column('commit_id', sa.String(128), primary_key=True, nullable=False), |
| 37 | sa.Column('committed_at', sa.DateTime(timezone=True), nullable=False), |
| 38 | sa.Column('author', sa.String(256), nullable=True), |
| 39 | sa.Column('op', sa.String(32), nullable=False), |
| 40 | sa.Column('content_id', sa.String(128), nullable=True), |
| 41 | ) |
| 42 | op.create_index('ix_symbol_history_repo_address', 'musehub_symbol_history_entries', ['repo_id', 'address']) |
| 43 | op.create_index('ix_symbol_history_repo_address_ts', 'musehub_symbol_history_entries', ['repo_id', 'address', 'committed_at']) |
| 44 | |
| 45 | op.create_table( |
| 46 | 'musehub_symbol_intel', |
| 47 | sa.Column('repo_id', sa.String(128), sa.ForeignKey('musehub_repos.repo_id', ondelete='CASCADE'), primary_key=True, nullable=False), |
| 48 | sa.Column('address', sa.String(512), primary_key=True, nullable=False), |
| 49 | sa.Column('churn', sa.Integer, nullable=False, server_default='0'), |
| 50 | sa.Column('churn_30d', sa.Integer, nullable=False, server_default='0'), |
| 51 | sa.Column('churn_90d', sa.Integer, nullable=False, server_default='0'), |
| 52 | sa.Column('blast', sa.Integer, nullable=False, server_default='0'), |
| 53 | sa.Column('blast_direct', sa.Integer, nullable=False, server_default='0'), |
| 54 | sa.Column('blast_cross', sa.Integer, nullable=False, server_default='0'), |
| 55 | sa.Column('blast_top', sa.ARRAY(sa.Text), nullable=False, server_default='{}'), |
| 56 | sa.Column('last_changed', sa.DateTime(timezone=True), nullable=True), |
| 57 | sa.Column('last_author', sa.String(256), nullable=True), |
| 58 | sa.Column('author_count', sa.Integer, nullable=False, server_default='0'), |
| 59 | sa.Column('gravity', sa.Float, nullable=False, server_default='0.0'), |
| 60 | sa.Column('weekly', sa.ARRAY(sa.Integer), nullable=False, server_default='{}'), |
| 61 | ) |
| 62 | op.create_index('ix_symbol_intel_repo_churn', 'musehub_symbol_intel', ['repo_id', 'churn']) |
| 63 | op.create_index('ix_symbol_intel_repo_gravity', 'musehub_symbol_intel', ['repo_id', 'gravity']) |
| 64 | |
| 65 | op.create_table( |
| 66 | 'musehub_hash_occurrence_entries', |
| 67 | sa.Column('content_id', sa.String(128), primary_key=True, nullable=False), |
| 68 | sa.Column('repo_id', sa.String(128), sa.ForeignKey('musehub_repos.repo_id', ondelete='CASCADE'), primary_key=True, nullable=False), |
| 69 | sa.Column('address', sa.String(512), primary_key=True, nullable=False), |
| 70 | ) |
| 71 | op.create_index('ix_hash_occurrence_repo_content', 'musehub_hash_occurrence_entries', ['repo_id', 'content_id']) |
| 72 | |
| 73 | # Remove stale blob types — will be rebuilt from normalized tables on next push. |
| 74 | op.execute(""" |
| 75 | DELETE FROM musehub_intel_results |
| 76 | WHERE intel_type IN ( |
| 77 | 'code.symbol_history', |
| 78 | 'code.per_symbol_intel', |
| 79 | 'code.hash_occurrence' |
| 80 | ) |
| 81 | """) |
| 82 | |
| 83 | |
| 84 | def downgrade() -> None: |
| 85 | op.drop_table('musehub_hash_occurrence_entries') |
| 86 | op.drop_table('musehub_symbol_intel') |
| 87 | op.drop_table('musehub_symbol_history_entries') |
File History
12 commits
sha256:cfefc25a166c3c3eed8ea3529aee19ea350bc05f2954d007420e924133b7d8ce
chore: pivot to nightly channel — bump version to 0.2.0.dev…
Sonnet 5
patch
13 days ago
sha256:d035733f21ccff27735fddebfbbe0ed24565a32a22db8de5885402262671ecd2
chore: bump version to 0.2.0rc15 for musehub#113 fix release
Sonnet 4.6
patch
15 days ago
sha256:0032d6cfa33bc3c8367436ad768e7dd0e339b4332153160247da8266cb5fa352
Merge branch 'task/version-tags-phase3-server' into dev
Human
17 days ago
sha256:4669620efda9ff41c55bdefd1f7bfe1c239d468428744c84ead9957e5a003a53
merge: rescue snapshot-recovery hardening (c00aa21d) into d…
Opus 4.8
minor
⚠
30 days ago
sha256:a59da49c4611b970fc4b6ae48678ce4943261c213a07ddbd73ce9201df869b4a
fix: remove false-positive proposal_comments index drop fro…
Sonnet 4.6
patch
34 days ago
sha256:0a240d6dbff234f07d98a28a4a9a68db702f3f9ff9260196f24219bdb1c0b6f3
feat: render markdown mists as HTML with heading anchor links
Sonnet 4.6
patch
34 days ago
sha256:24a7d47486ebc4ebd1832830580e177ec6f877b48dced8c000e198cdec4ce9d6
Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump …
Human
36 days ago
sha256:b9ff931d147e0114a1f17060f415b89ed551c170a91ff226c70437aa5c85f9ee
Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump …
Human
36 days ago
sha256:d1122d21e73471879b460037b22c0b50fded7c423444a176f248428f75dac39c
Merge 'task/fix-issue-pagination-cursor' into 'dev' — propo…
Human
36 days ago
sha256:01e18975e73d2b3cd5b6db7929c895bef9aa6e0d4391dc5b2adfc548b41318dd
Merge 'feat/adding-debug-logs-to-staging' into 'dev' — prop…
Human
36 days ago
sha256:6b1949fc2797ca4c1936a637a4cbfec828ef56cf52398a2e74ca3c4f494e728f
fix: use wire_bytes not mpack_bytes_raw in compute_object_b…
Sonnet 4.6
patch
48 days ago
sha256:b99f2455dc346966d040133f5203297e6e3ef5803a93728a2c30568d0a0f7583
rename: delta_add → delta_upsert across wire format, models…
Sonnet 4.6
patch
50 days ago