gabriel / musehub public
0013_snapshot_entries_replace_manifest.py python
60 lines 2.0 KB
Raw
sha256:a10adeeb7a0169cb9900f9806ed7a973047258abb6283724fe55e8eb68ff3f0a init: musehub initial commit Human 171 days ago
1 """Phase 7: replace musehub_snapshots.manifest blob with normalized musehub_snapshot_entries table.
2
3 Revision ID: 0013
4 Revises: 0012
5 """
6
7 from alembic import op
8 import sqlalchemy as sa
9
10 revision = "0013"
11 down_revision = "0012"
12 branch_labels = None
13 depends_on = None
14
15
16 def upgrade() -> None:
17 # ── musehub_snapshot_entries ──────────────────────────────────────────────
18 op.create_table(
19 "musehub_snapshot_entries",
20 sa.Column("snapshot_id", sa.String(128), primary_key=True),
21 sa.Column("path", sa.String(1024), primary_key=True),
22 sa.Column("object_id", sa.String(128), nullable=False),
23 sa.Column("size_bytes", sa.Integer(), nullable=False, server_default="0"),
24 sa.ForeignKeyConstraint(
25 ["snapshot_id"],
26 ["musehub_snapshots.snapshot_id"],
27 ondelete="CASCADE",
28 ),
29 )
30 op.create_index(
31 "ix_musehub_snapshot_entries_snapshot_id",
32 "musehub_snapshot_entries",
33 ["snapshot_id"],
34 )
35 op.create_index(
36 "ix_musehub_snapshot_entries_object_id",
37 "musehub_snapshot_entries",
38 ["object_id"],
39 )
40
41 # ── drop the manifest JSON blob ───────────────────────────────────────────
42 # All existing manifests are {} (empty) — the wire_push bug meant they were
43 # never populated — so there is no data to migrate.
44 op.drop_column("musehub_snapshots", "manifest")
45
46
47 def downgrade() -> None:
48 op.add_column(
49 "musehub_snapshots",
50 sa.Column("manifest", sa.JSON(), nullable=False, server_default="{}"),
51 )
52 op.drop_index(
53 "ix_musehub_snapshot_entries_object_id",
54 table_name="musehub_snapshot_entries",
55 )
56 op.drop_index(
57 "ix_musehub_snapshot_entries_snapshot_id",
58 table_name="musehub_snapshot_entries",
59 )
60 op.drop_table("musehub_snapshot_entries")
File History 1 commit
sha256:a10adeeb7a0169cb9900f9806ed7a973047258abb6283724fe55e8eb68ff3f0a init: musehub initial commit Human 171 days ago