-- Per-page row for each uploaded chapter. The reader needs to know each -- page's storage key (extensions can vary across pages within a chapter -- because uploads sniff and preserve per-image MIME), so we store one -- row per page rather than re-deriving keys from a fixed pattern. CREATE TABLE pages ( id uuid PRIMARY KEY DEFAULT gen_random_uuid(), chapter_id uuid NOT NULL REFERENCES chapters(id) ON DELETE CASCADE, page_number integer NOT NULL, storage_key text NOT NULL, content_type text NOT NULL, UNIQUE (chapter_id, page_number) ); CREATE INDEX pages_chapter_idx ON pages (chapter_id, page_number);