gabriel / musehub public

0062_pack_index_global.py file-level

at sha256:7 · View file ↗ · Intel ↗

History
1 files
1 commits
0 hotspots
0 🧊 dead
0 💥 blast risk
sha256:0 fix: fall back to any indexed mpack in read_object_bytes when push mpac… · gabriel · Jun 17, 2026
1 """Make musehub_pack_index global — drop repo_id column and its FK.
2
3 Pack index entries are content-addressed: the same object_id+pack_id pair is valid
4 for every repo that has ever pushed those bytes. repo_id was the wrong abstraction
5 and caused wire_fetch_mpack to miss packs from other repos (same objects, different repo).
6
7 PK (object_id, pack_id) is unchanged. Drop the (repo_id, object_id) index and replace
8 it with a plain object_id index — lookups are now global, not per-repo.
9 """
10
11 from __future__ import annotations
12
13 import sqlalchemy as sa
14 from alembic import op
15
16 revision = "0062"
17 down_revision = "0061"
18 branch_labels = None
19 depends_on = None
20
21
22 def upgrade() -> None:
23 op.drop_index("ix_musehub_pack_index_repo_object", table_name="musehub_pack_index")
24 op.drop_constraint("musehub_pack_index_repo_id_fkey", "musehub_pack_index", type_="foreignkey")
25 op.drop_column("musehub_pack_index", "repo_id")
26 op.create_index("ix_musehub_pack_index_object_id", "musehub_pack_index", ["object_id"])
27
28
29 def downgrade() -> None:
30 op.drop_index("ix_musehub_pack_index_object_id", table_name="musehub_pack_index")
31 op.add_column(
32 "musehub_pack_index",
33 sa.Column("repo_id", sa.String(128), nullable=False, server_default=""),
34 )
35 op.create_foreign_key(
36 "musehub_pack_index_repo_id_fkey",
37 "musehub_pack_index", "musehub_repos",
38 ["repo_id"], ["repo_id"],
39 ondelete="CASCADE",
40 )
41 op.create_index(
42 "ix_musehub_pack_index_repo_object",
43 "musehub_pack_index",
44 ["repo_id", "object_id"],
45 )