0058_commits_snapshots_global.py
python
sha256:34035d72cef530c1ab9d6a6f53be18d803dde705fc3157617d70352a96d0747b
Merge branch 'fix/wire-push-external-parent-manifest' into dev
Human
8 days ago
| 1 | """Make commits and snapshots globally content-addressed — remove repo_id. |
| 2 | |
| 3 | Commits and snapshots are content-addressed objects identified by their SHA-256 |
| 4 | hash alone. They do not belong to any repo. Repo membership is tracked in |
| 5 | separate ref tables (musehub_commit_refs, musehub_snapshot_refs), exactly |
| 6 | mirroring how musehub_object_refs tracks object membership. |
| 7 | |
| 8 | Changes: |
| 9 | - Drop repo_id FK + composite indexes from musehub_commits |
| 10 | - Drop repo_id FK + index from musehub_snapshots |
| 11 | - Create musehub_commit_refs (repo_id, commit_id) |
| 12 | - Create musehub_snapshot_refs (repo_id, snapshot_id) |
| 13 | - Backfill both ref tables from existing rows |
| 14 | """ |
| 15 | |
| 16 | from __future__ import annotations |
| 17 | |
| 18 | import sqlalchemy as sa |
| 19 | from alembic import op |
| 20 | |
| 21 | revision = "0058" |
| 22 | down_revision = "0057" |
| 23 | branch_labels = None |
| 24 | depends_on = None |
| 25 | |
| 26 | |
| 27 | def upgrade() -> None: |
| 28 | # ── 1. Create musehub_commit_refs ──────────────────────────────────────── |
| 29 | op.create_table( |
| 30 | "musehub_commit_refs", |
| 31 | sa.Column("repo_id", sa.String(128), sa.ForeignKey("musehub_repos.repo_id", ondelete="CASCADE"), primary_key=True), |
| 32 | sa.Column("commit_id", sa.String(128), sa.ForeignKey("musehub_commits.commit_id", ondelete="CASCADE"), primary_key=True), |
| 33 | sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()), |
| 34 | ) |
| 35 | op.create_index("ix_musehub_commit_refs_repo_id", "musehub_commit_refs", ["repo_id"]) |
| 36 | |
| 37 | # ── 2. Create musehub_snapshot_refs ────────────────────────────────────── |
| 38 | op.create_table( |
| 39 | "musehub_snapshot_refs", |
| 40 | sa.Column("repo_id", sa.String(128), sa.ForeignKey("musehub_repos.repo_id", ondelete="CASCADE"), primary_key=True), |
| 41 | sa.Column("snapshot_id", sa.String(128), sa.ForeignKey("musehub_snapshots.snapshot_id", ondelete="CASCADE"), primary_key=True), |
| 42 | sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()), |
| 43 | ) |
| 44 | op.create_index("ix_musehub_snapshot_refs_repo_id", "musehub_snapshot_refs", ["repo_id"]) |
| 45 | |
| 46 | # ── 3. Backfill commit refs from existing musehub_commits rows ──────────── |
| 47 | op.execute( |
| 48 | """ |
| 49 | INSERT INTO musehub_commit_refs (repo_id, commit_id, created_at) |
| 50 | SELECT repo_id, commit_id, now() |
| 51 | FROM musehub_commits |
| 52 | ON CONFLICT DO NOTHING |
| 53 | """ |
| 54 | ) |
| 55 | |
| 56 | # ── 4. Backfill snapshot refs from existing musehub_snapshots rows ──────── |
| 57 | op.execute( |
| 58 | """ |
| 59 | INSERT INTO musehub_snapshot_refs (repo_id, snapshot_id, created_at) |
| 60 | SELECT repo_id, snapshot_id, now() |
| 61 | FROM musehub_snapshots |
| 62 | ON CONFLICT DO NOTHING |
| 63 | """ |
| 64 | ) |
| 65 | |
| 66 | # ── 5. Drop composite indexes on musehub_commits ───────────────────────── |
| 67 | op.drop_index("ix_musehub_commits_repo_branch", table_name="musehub_commits") |
| 68 | op.drop_index("ix_musehub_commits_repo_timestamp", table_name="musehub_commits") |
| 69 | |
| 70 | # ── 6. Drop repo_id FK + column from musehub_commits ───────────────────── |
| 71 | op.drop_constraint("musehub_commits_repo_id_fkey", "musehub_commits", type_="foreignkey") |
| 72 | op.drop_index("ix_musehub_commits_repo_id", table_name="musehub_commits") |
| 73 | op.drop_column("musehub_commits", "repo_id") |
| 74 | |
| 75 | # ── 7. Drop repo_id FK + column from musehub_snapshots ─────────────────── |
| 76 | op.drop_constraint("musehub_snapshots_repo_id_fkey", "musehub_snapshots", type_="foreignkey") |
| 77 | op.drop_index("ix_musehub_snapshots_repo_id", table_name="musehub_snapshots") |
| 78 | op.drop_column("musehub_snapshots", "repo_id") |
| 79 | |
| 80 | |
| 81 | def downgrade() -> None: |
| 82 | # Re-add repo_id to musehub_snapshots (data loss — refs table is lost) |
| 83 | op.add_column("musehub_snapshots", sa.Column("repo_id", sa.String(128), nullable=True)) |
| 84 | op.create_foreign_key( |
| 85 | "musehub_snapshots_repo_id_fkey", "musehub_snapshots", |
| 86 | "musehub_repos", ["repo_id"], ["repo_id"], ondelete="CASCADE", |
| 87 | ) |
| 88 | op.create_index("ix_musehub_snapshots_repo_id", "musehub_snapshots", ["repo_id"]) |
| 89 | |
| 90 | # Re-add repo_id to musehub_commits |
| 91 | op.add_column("musehub_commits", sa.Column("repo_id", sa.String(128), nullable=True)) |
| 92 | op.create_foreign_key( |
| 93 | "musehub_commits_repo_id_fkey", "musehub_commits", |
| 94 | "musehub_repos", ["repo_id"], ["repo_id"], ondelete="CASCADE", |
| 95 | ) |
| 96 | op.create_index("ix_musehub_commits_repo_id", "musehub_commits", ["repo_id"]) |
| 97 | op.create_index("ix_musehub_commits_repo_branch", "musehub_commits", ["repo_id", "branch"]) |
| 98 | op.create_index("ix_musehub_commits_repo_timestamp","musehub_commits", ["repo_id", "timestamp"]) |
| 99 | |
| 100 | op.drop_index("ix_musehub_snapshot_refs_repo_id", table_name="musehub_snapshot_refs") |
| 101 | op.drop_table("musehub_snapshot_refs") |
| 102 | op.drop_index("ix_musehub_commit_refs_repo_id", table_name="musehub_commit_refs") |
| 103 | op.drop_table("musehub_commit_refs") |
File History
14 commits
sha256:34035d72cef530c1ab9d6a6f53be18d803dde705fc3157617d70352a96d0747b
Merge branch 'fix/wire-push-external-parent-manifest' into dev
Human
8 days ago
sha256:fc04e4cae9e1774d6a21b65c45daeed0e6787eb581d13aa1b03bfe9384a34226
Merge branch 'fix/two-column-scroll-layout' into dev
Human
8 days ago
sha256:408916fc5973ba59c6e4eebaa80ebdcc801c0a63205651e25009d11548f79454
chore: bump version to 0.2.0.dev2 — nightly.2, matching muse
Sonnet 4.6
patch
11 days ago
sha256:d035733f21ccff27735fddebfbbe0ed24565a32a22db8de5885402262671ecd2
chore: bump version to 0.2.0rc15 for musehub#113 fix release
Sonnet 4.6
patch
14 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
⚠
29 days ago
sha256:a59da49c4611b970fc4b6ae48678ce4943261c213a07ddbd73ce9201df869b4a
fix: remove false-positive proposal_comments index drop fro…
Sonnet 4.6
patch
33 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
35 days ago
sha256:b9ff931d147e0114a1f17060f415b89ed551c170a91ff226c70437aa5c85f9ee
Merge 'task/bump-version-rc12' into 'dev' — proposal: Bump …
Human
35 days ago
sha256:d1122d21e73471879b460037b22c0b50fded7c423444a176f248428f75dac39c
Merge 'task/fix-issue-pagination-cursor' into 'dev' — propo…
Human
35 days ago
sha256:01e18975e73d2b3cd5b6db7929c895bef9aa6e0d4391dc5b2adfc548b41318dd
Merge 'feat/adding-debug-logs-to-staging' into 'dev' — prop…
Human
35 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