"""documents.page_count: the rendered page-strip's page count (phase 148, task 01) Revision ID: 0026 Revises: 0025 Create Date: 2026-10-01 Phase 148 (pictorial PDFs show their PAGES in the sources — task 01, storage only): * ``documents.page_count`` — INTEGER NULLABLE, NO server default, NO index: the number of rendered page PNGs persisted in ``settings.pdf_page_dir`` (``BOR_PDF_PAGE_DIR``) as ``-p{N}.png`` (N 1-based) for ONE page-qualifying document — the PDF's page count. Set ONLY by the importer's PDF branch (task 01): a qualifying PDF (the phase-133 fallback class — unusable text layer, — or the phase-140 pictorial class — the sparse-page pass described ≥1 page) gets every page rendered at index time, and this column records the page count (a per-page render failure leaves a GAP — the file is simply absent, the route of task 02 404s that N, the viewer's note covers it). NULL for every other document (text documents, images, text-heavy PDFs) and for a qualifying PDF whose render/write failed (fail-soft — the render is a display concern, it never gates indexing); the prune cleanup deletes the copies with the row. A display fact, never a query surface: the page-bytes route (task 02) looks the document up by its uuid4 id FIRST (the unguessable id is the credential — the phase-124 image-route trust model) and reads this column from the ROW, so it carries no index of its own (the ``file_hash`` convention, 0025). One additive, fully reversible migration (A13); no other schema change. The render/persist/cleanup logic itself (task 01) is importer code — this revision only carries the column. """ from __future__ import annotations import sqlalchemy as sa from alembic import op revision = "0026" down_revision = "0025" branch_labels = None depends_on = None def upgrade() -> None: # No index (a display fact, never a query surface — the page route # reads it from the row after the uuid4 id lookup) and no server # default (NULL is the meaningful state for every non-qualifying # document and every fail-soft miss). op.add_column("documents", sa.Column("page_count", sa.Integer(), nullable=True)) def downgrade() -> None: # The page_count column is the only 0026 artefact — dropping it # leaves 0025's schema byte-identical (A13, fully reversible). The # rendered copies are re-derivable from the source files on the # next sync, so no data is lost by the drop. op.drop_column("documents", "page_count")