gabriel / musehub public
0015_intel_cache.py python
66 lines 2.0 KB
Raw
sha256:a10adeeb7a0169cb9900f9806ed7a973047258abb6283724fe55e8eb68ff3f0a init: musehub initial commit Human 172 days ago
1 """Add intel_full_json to symbol index + file-level intel cache table.
2
3 intel_full_json: full serialized IntelSnapshot stored at push time so any
4 page that needs repo-level intel never has to load the msgpack blob or run
5 compute_intel at request time.
6
7 musehub_file_intel_cache: per-file intel cache keyed by (repo_id, file_path).
8 The ref column stores the symbol index commit_id at which the cache was built.
9 Rows are invalidated on push by deleting all rows for the repo.
10
11 Revision ID: 0015
12 Revises: 0014
13 """
14
15 from alembic import op
16 import sqlalchemy as sa
17
18 revision = "0015"
19 down_revision = "0014"
20 branch_labels = None
21 depends_on = None
22
23
24 def upgrade() -> None:
25 op.add_column(
26 "musehub_symbol_index",
27 sa.Column("intel_full_json", sa.Text(), nullable=True),
28 )
29
30 op.create_table(
31 "musehub_file_intel_cache",
32 sa.Column("cache_id", sa.String(36), primary_key=True),
33 sa.Column(
34 "repo_id",
35 sa.String(36),
36 sa.ForeignKey("musehub_repos.repo_id", ondelete="CASCADE"),
37 nullable=False,
38 ),
39 sa.Column("file_path", sa.String(1024), nullable=False),
40 sa.Column("ref", sa.String(64), nullable=False),
41 sa.Column("intel_json", sa.Text(), nullable=False),
42 sa.Column("symbol_history_json", sa.Text(), nullable=False),
43 sa.Column(
44 "computed_at",
45 sa.DateTime(timezone=True),
46 nullable=False,
47 ),
48 )
49 op.create_index(
50 "ix_file_intel_cache_repo_path",
51 "musehub_file_intel_cache",
52 ["repo_id", "file_path"],
53 unique=True,
54 )
55 op.create_index(
56 "ix_file_intel_cache_repo_id",
57 "musehub_file_intel_cache",
58 ["repo_id"],
59 )
60
61
62 def downgrade() -> None:
63 op.drop_index("ix_file_intel_cache_repo_id", table_name="musehub_file_intel_cache")
64 op.drop_index("ix_file_intel_cache_repo_path", table_name="musehub_file_intel_cache")
65 op.drop_table("musehub_file_intel_cache")
66 op.drop_column("musehub_symbol_index", "intel_full_json")
File History 1 commit
sha256:a10adeeb7a0169cb9900f9806ed7a973047258abb6283724fe55e8eb68ff3f0a init: musehub initial commit Human 172 days ago