gabriel / musehub public
0019_commit_provenance_columns.py python
53 lines 1.5 KB
Raw
sha256:94ef169c149a452bff7c604ded8b280b19bd477c2dabcb56972780b0b784c7aa Merge 'fix/assignee-sigil-inline' into 'dev' — proposal: As… Human 2 days ago
1 """Promote agent_id, model_id, commit_branch to first-class columns on musehub_commits.
2
3 These were previously buried in the commit_meta JSON blob, making them
4 unqueryable without JSON extraction. Promoting them enables indexed lookups
5 and clean UI display.
6
7 Revision ID: 0019
8 Revises: 0018
9 Create Date: 2026-05-04
10 """
11 from __future__ import annotations
12
13 from alembic import op
14 import sqlalchemy as sa
15
16 revision = "0019"
17 down_revision = "0018"
18 branch_labels = None
19 depends_on = None
20
21
22 def upgrade() -> None:
23 op.add_column(
24 "musehub_commits",
25 sa.Column("agent_id", sa.String(255), nullable=True, server_default=""),
26 )
27 op.add_column(
28 "musehub_commits",
29 sa.Column("model_id", sa.String(255), nullable=True, server_default=""),
30 )
31 op.add_column(
32 "musehub_commits",
33 sa.Column("commit_branch", sa.String(255), nullable=True),
34 )
35 # Backfill from commit_meta JSON for all existing rows
36 op.execute(
37 """
38 UPDATE musehub_commits
39 SET
40 agent_id = COALESCE(commit_meta->>'agent_id', ''),
41 model_id = COALESCE(commit_meta->>'model_id', ''),
42 commit_branch = NULLIF(commit_meta->>'branch', '')
43 WHERE agent_id IS NULL OR agent_id = ''
44 OR model_id IS NULL OR model_id = ''
45 OR commit_branch IS NULL
46 """
47 )
48
49
50 def downgrade() -> None:
51 from sqlalchemy import text
52 for col in ("commit_branch", "model_id", "agent_id"):
53 op.execute(text(f"ALTER TABLE musehub_commits DROP COLUMN IF EXISTS {col}"))
File History 3 commits
sha256:94ef169c149a452bff7c604ded8b280b19bd477c2dabcb56972780b0b784c7aa Merge 'fix/assignee-sigil-inline' into 'dev' — proposal: As… Human 2 days ago
sha256:6b1949fc2797ca4c1936a637a4cbfec828ef56cf52398a2e74ca3c4f494e728f fix: use wire_bytes not mpack_bytes_raw in compute_object_b… Sonnet 4.6 patch 10 days ago
sha256:4aed3d8601c8dd3ed37074de35f11f4a9699a0a4b99d43727048fd3f8e6fd13d chore: doc sweep, ignore wrangler build state, misc fixes Sonnet 4.6 minor 13 days ago