feat: partial indexes for mermaid blocks and architecture notes (#252) #253
No reviewers
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ldraney/pal-e-api!253
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "252-partial-indexes-mermaid-architecture"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Changes
alembic/versions/u1p2q3r4s5t6_add_mermaid_and_architecture_partial_indexes.py— new migrationdown_revision = "t0o1p2q3r4s5"(verified viaalembic headsbefore writing)ix_blocks_block_type_mermaidonblocks(block_type) WHERE block_type = 'mermaid'ix_notes_note_type_architectureonnotes(note_type) WHERE note_type = 'architecture'op.create_index(..., postgresql_where=sa.text("..."))src/pal_e_docs/models.pyintentionally untouched — SQLAlchemy's nativeIndexdoesn't cleanly expressWHEREclauses, and per the spec partial indexes are migration-only.Test Plan
alembic upgrade head && alembic downgrade -1 && alembic upgrade headclean against a freshpgvector/pgvector:pg17container\d blocksshowsix_blocks_block_type_mermaid btree (block_type) WHERE block_type::text = 'mermaid'::textpg_indexesconfirms both partial indexes with correctWHEREpredicatesruff formatandruff checkclean on the new filemodels.pyEXPLAIN evidence (with
SET enable_seqscan = off)Per the spec, at current row counts the planner may legitimately prefer Seq Scan; disabling seqscan is the deterministic way to verify the partial indexes are query-planner-visible.
Both queries resolve to
Index Scan using <partial-index>— the smoking-gun evidence the indexes exist and are query-planner-visible.Review Checklist
Related Notes
forgejo_admin/pal-e-api #252— the Forgejo issue this PR implements (scope reviewreview-944-2026-04-10-r2APPROVED)project-pal-e-docs— the project this work belongs toarch-domain-pal-e-docs— backing architecture note; affectsarch:blocksandarch:notescomponentsstory:superuser-query— traces to this user storytemplate-architecture— prescribes the diagram triplet these indexes coverCreates two partial btree indexes declaring the mermaid-block and architecture-note query paths as first-class at the schema level: - ix_blocks_block_type_mermaid ON blocks(block_type) WHERE block_type = 'mermaid' - ix_notes_note_type_architecture ON notes(note_type) WHERE note_type = 'architecture' Motivation is semantic self-documentation (not performance) — at current scale the planner may prefer Seq Scan, so the partial indexes serve as schema-level declarations that these subsets are query-worthy. Refs #252. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>PR #253 Review
DOMAIN REVIEW (Alembic migration)
Tech stack: Python / Alembic / SQLAlchemy / Postgres. Applied migration + partial-index domain checks.
Correctness:
op.create_index(..., postgresql_where=sa.text("..."))— not rawop.execute("CREATE INDEX ..."). This is the preferred Alembic pattern.down_revision = "t0o1p2q3r4s5"— PR body states this was verified viaalembic headsbefore writing. Single-file diff means no chain mutation introduced; linearity preserved.ix_<table>_<columns>_<discriminator>convention:ix_blocks_block_type_mermaidonblocks(block_type) WHERE block_type = 'mermaid'ix_notes_note_type_architectureonnotes(note_type) WHERE note_type = 'architecture'src/pal_e_docs/models.pyis NOT touched — confirmed by 1-file diff. Matches spec constraint exactly (SQLAlchemy's nativeIndexcan't cleanly express partialWHERE, and the spec explicitly scopes this to migration-only).u1p2q3r4s5t6follows the sequential alphabetic pattern used throughoutalembic/versions/.postgresql_where=sa.text(...)predicate is unqualified text — Postgres parses/stores it asblock_type::text = 'mermaid'::text(PR body's\d blocksoutput confirms the rendered form). Correct behavior.EXPLAIN evidence:
SET enable_seqscan = offis the right deterministic way to prove partial-index visibility at current row counts (~25 rows per slice) where the planner would otherwise legitimately prefer Seq Scan. This matches the spec's guidance.Index Scan using <partial-index>— smoking-gun evidence. Good.Up/down roundtrip:
alembic upgrade head && alembic downgrade -1 && alembic upgrade headclean againstpgvector/pgvector:pg17.BLOCKERS
None.
NITS (non-blocking)
ix_blocks_block_type_mermaidsomehow already exists (e.g., partial apply from a prior aborted run),op.create_indexwill error. For a greenfield migration this is fine, but future migrations of this shape could benefit frompostgresql_using="btree"explicitness and/or a pre-check. Not worth changing here.models.pyis untouched. Keep doing this.SOP COMPLIANCE
252-partial-indexes-mermaid-architecture— matches{issue}-{kebab-purpose}conventionreview-944-2026-04-10-r2(APPROVED),project-pal-e-docs,arch-domain-pal-e-docs,story:superuser-query,template-architectureenable_seqscan = off)feat: partial indexes for mermaid blocks and architecture notes (#252))PROCESS OBSERVATIONS
t0o1p2q3r4s5prior head from my stale local checkout (my local showss9n0o1p2q3r4as latest, suggesting a migration landed on main I don't see). Trusting the PR body's claim thatalembic headswas checked; the 1-file diff rules out any local chain mutation. If CI runsalembic upgrade headagainst a fresh DB this will self-verify.VERDICT: APPROVED