gabriel / musehub public
0003_wire_and_identities.py python
127 lines 4.7 KB
cb3d85e8 feat: wire protocol, storage abstraction, unified identities, Qdrant pi… Gabriel Cardona <cgcardona@gmail.com> 4d ago
1 """Wire protocol support + unified identities table.
2
3 Revision ID: 0003
4 Revises: 0002
5 Create Date: 2026-03-19
6
7 Changes:
8 NEW TABLES
9 - musehub_snapshots: Immutable file-tree manifests (path → object_id JSON)
10 - musehub_identities: Unified identity table for humans, agents, and orgs
11
12 MUSEHUB_COMMITS
13 - ADD commit_meta JSON (stores rich Muse-native fields: sem_ver_bump,
14 structured_delta, breaking_changes, agent_id, model_id, etc.)
15
16 MUSEHUB_OBJECTS
17 - ADD storage_uri (storage backend URI: "local://..." | "s3://...")
18
19 MUSEHUB_REPOS
20 - ADD default_branch VARCHAR(255) DEFAULT 'main'
21 - ADD pushed_at TIMESTAMP WITH TIME ZONE (last push time for trending sort)
22 """
23 import sqlalchemy as sa
24 from alembic import op
25
26
27 revision = "0003"
28 down_revision = "0002"
29 branch_labels = None
30 depends_on = None
31
32
33 def upgrade() -> None:
34 # ── musehub_snapshots ────────────────────────────────────────────────────
35 op.create_table(
36 "musehub_snapshots",
37 sa.Column("snapshot_id", sa.String(128), primary_key=True),
38 sa.Column(
39 "repo_id",
40 sa.String(36),
41 sa.ForeignKey("musehub_repos.repo_id", ondelete="CASCADE"),
42 nullable=False,
43 ),
44 sa.Column("manifest", sa.JSON(), nullable=False, server_default="{}"),
45 sa.Column(
46 "created_at",
47 sa.DateTime(timezone=True),
48 nullable=False,
49 server_default=sa.text("NOW()"),
50 ),
51 )
52 op.create_index(
53 "ix_musehub_snapshots_repo_id",
54 "musehub_snapshots",
55 ["repo_id"],
56 )
57
58 # ── musehub_identities ───────────────────────────────────────────────────
59 op.create_table(
60 "musehub_identities",
61 sa.Column("id", sa.String(36), primary_key=True),
62 sa.Column("handle", sa.String(64), nullable=False),
63 sa.Column("identity_type", sa.String(16), nullable=False, server_default="human"),
64 sa.Column("display_name", sa.String(255), nullable=True),
65 sa.Column("bio", sa.Text(), nullable=True),
66 sa.Column("avatar_url", sa.String(2048), nullable=True),
67 sa.Column("website_url", sa.String(2048), nullable=True),
68 sa.Column("email", sa.String(255), nullable=True),
69 sa.Column("agent_model", sa.String(255), nullable=True),
70 sa.Column("agent_capabilities", sa.JSON(), nullable=False, server_default="[]"),
71 sa.Column("legacy_user_id", sa.String(36), nullable=True),
72 sa.Column(
73 "created_at",
74 sa.DateTime(timezone=True),
75 nullable=False,
76 server_default=sa.text("NOW()"),
77 ),
78 sa.Column(
79 "updated_at",
80 sa.DateTime(timezone=True),
81 nullable=False,
82 server_default=sa.text("NOW()"),
83 ),
84 sa.Column("deleted_at", sa.DateTime(timezone=True), nullable=True),
85 )
86 op.create_index("ix_musehub_identities_handle", "musehub_identities", ["handle"])
87 op.create_index("ix_musehub_identities_email", "musehub_identities", ["email"])
88 op.create_index("ix_musehub_identities_legacy_user_id", "musehub_identities", ["legacy_user_id"])
89 op.create_unique_constraint(
90 "uq_musehub_identities_handle", "musehub_identities", ["handle"]
91 )
92
93 # ── musehub_commits — add commit_meta ────────────────────────────────────
94 op.add_column(
95 "musehub_commits",
96 sa.Column("commit_meta", sa.JSON(), nullable=False, server_default="{}"),
97 )
98
99 # ── musehub_objects — add storage_uri ────────────────────────────────────
100 op.add_column(
101 "musehub_objects",
102 sa.Column("storage_uri", sa.String(2048), nullable=True),
103 )
104
105 # ── musehub_repos — add default_branch + pushed_at ───────────────────────
106 op.add_column(
107 "musehub_repos",
108 sa.Column(
109 "default_branch",
110 sa.String(255),
111 nullable=False,
112 server_default="main",
113 ),
114 )
115 op.add_column(
116 "musehub_repos",
117 sa.Column("pushed_at", sa.DateTime(timezone=True), nullable=True),
118 )
119
120
121 def downgrade() -> None:
122 op.drop_column("musehub_repos", "pushed_at")
123 op.drop_column("musehub_repos", "default_branch")
124 op.drop_column("musehub_objects", "storage_uri")
125 op.drop_column("musehub_commits", "commit_meta")
126 op.drop_table("musehub_identities")
127 op.drop_table("musehub_snapshots")