gabriel / musehub public

0019_commit_provenance_columns.py file-level

at dev · View file ↗ · Intel ↗

History
1 files
1 commits
0 hotspots
0 🧊 dead
0 💥 blast risk
sha256:9 Merge 'fix/assignee-sigil-inline' into 'dev' — proposal: Assignee sigil… · gabriel · Jun 7, 2026
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}"))