Replies: 8 comments 5 replies
I would suggest the term "concrete" rather than "physical" to avoid conflation. |
Should I take this literally? Would we be renaming the existing table to something else?
What would happen to those fields on the existing table? Do you have suggested final schemas for these tables? |
So this would need to be a task that migrates somehow? Or how else would we do this? Eventual consistency? |
How would this gradual rollout work? Do you mean that we'd implement a new feature flagging solution? Or we'd keep the APIs following the same responses? |
|
Does this have any interactions with the "folder based" settings for a library? Or is that only for the semantics of scanning rather than how we need to store book files? |
This Work / Edition model is mentioned a few times, but there is no link to any relevant discussion / RFC. Can we add it so that people without familiarity with it can have the full picture? Thanks! |
I'd strongly recommend for all the main refactoring RFCs that will touch the data model to include detailed ER diagrams (Mermaid is a good option) with comprehensive coverage of all the fields / attributes and clarifying the nature of relationships (1-to-1, 1-to-many, etc). It makes it so much easier to reason about them and to ensure all details are properly considered compared to a text description, which will always have some gaps or things "taken for granted". |
As a side note, this is quite important: I noticed the other day that physical books appear in the OPDS API/catalogue, but of course they can't be downloaded, therefore causing confusion. I wonder if we should consider adding a layer (likely at the application level) to map characteristics per format. e.g. physical books cannot be read / downloaded / streamed, audiobooks cannot be read, etc. Caveat: it's been a while since I've looked at the code, so something might be there already, but if not, this refactor could consider making that logic more robust than it is today |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
RFC: Book File Format / Issue Abstraction
Problem statement
Grimmory currently overloads the
book_filemodel to represent both "this book is available in this format" and "this exact file or folder exists on disk." That works for single-file ebooks, documents, and comics, but it breaks down when a representation needs more than one file.The clearest example today is multi-file audiobooks. A multi-file audiobook is collapsed into one
book_filerow withis_folder_based = true, while individual audio files are rediscovered from the filesystem whenever the system needs track-level data. That means Grimmory cannot reliably persist track order, per-file metadata, include/exclude state, per-file deletion/download state, or repeatable M4B/metadata-embedding inputs.Audiobooks are the immediate reason to do this, but the abstraction should stay general. Grimmory may later track sidecar Readium manifest JSON, guided navigation packages, generated outputs (such as transcriptions), or other format-specific files. Those are easier to manage if Grimmory distinguishes a book's logical representation from the files that belong to it.
This RFC proposes splitting the current
book_fileabstraction into two layers:This should not be a full rewrite of Grimmory's book model. The goal is to make the existing "this book has this format" concept explicit, then allow that format/issue to own multiple tracked files. This keeps the door open for a future Work / Edition model, but does not scope that broader work.
Goals
Non-goals
Proposed solution
Replace the current "one
book_filerow equals one file or folder" assumption with a model where a logical representation can own one or more concrete files.This should be a pragmatic migration, not a deep remodel. The first pass should keep the current
Book -> available formatsmental model and insert one level beneath it:That means the first implementation should avoid pulling in the full Work / Edition hierarchy. It should also avoid making every concrete file look like a top-level format. A multi-file audiobook should be one audiobook format/issue with many file rows, not many audiobook formats.
The final names should be decided during implementation, but the conceptual model could look like this:
Examples:
The existing
book_filetable can either be renamed/reframed as the issue/format table, or replaced by a new table with a compatibility view/mapper. The important requirement is that the logical representation is no longer forced to be the same row as the concrete file. The simplest viable shape is:001.mp3,002.mp3, and003.mp3What are the high level architectural changes?
BookEntityWhat are the high level data model changes?
Add or refactor toward a logical issue/format table with fields such as:
idbook_idbook_type/formatdisplay_nameis_primaryis_physicaladded_ondescriptionAdd a concrete file table using the file-specific fields that currently live on
book_file, such as path, filename, size, hashes, technical metadata, and missing/deleted state.For the first migration, existing single-file
book_filerows should become one issue/format row with one child file row. Existing folder-based audiobook rows should become one audiobook issue/format row with one child file row per audio file in the folder. That should be the primary focus; deeper metadata-specific improvements can remain follow-up work.What are the main changes to the UI?
This RFC should mostly preserve existing UI behaviour. It should add or prepare small compatibility changes:
Risks
Are there any backwards-incompatible changes?
Yes, potentially, but the first pass should stay small. The current database and many APIs assume
book_fileis both the format and the concrete file. The rollout should preserve current API response shapes where possible and introduce new issue/file-aware APIs before removing or renaming old fields.Special attention is needed for:
book_file_idDoes this project have special implications for security and data privacy?
Yes. The new file layer will become the source of truth for filesystem paths, deletion, downloads, and file mutation. Permission checks must remain at least as strict as today, and API responses should avoid exposing more filesystem path detail than existing endpoints intentionally expose.
Could this change significantly increase load on any of our backend systems?
The migration and initial scan/backfill may increase load. After rollout, the model should reduce repeated filesystem reads for multi-file formats because Grimmory can read track/file state from the database.
Does this project have any dependencies?
This RFC should land before rich audiobook functionality. It does not depend on the full Work / Edition model, but it should use terminology and boundaries that can migrate cleanly into that model later.
Alternative solutions
One alternative is to keep
book_fileas-is and add an audiobook-specificaudiobook_tracktable. That would unblock some audiobook work, but it would create a one-off model and leave the same abstraction problem for other multi-file representations.Another alternative is to wait for the full Work / Edition migration. That may be architecturally cleaner long-term, but it blocks practical improvements like rich audiobook management. This RFC creates a smaller seam that can later become the issue/manifestation/media-object layer.
Another alternative is to keep rediscovering multi-file formats from the filesystem. That avoids a migration, but it makes ordering, missing-file handling, per-file actions, and repeatable processing unreliable.
Implementation and rollout plan
book_fileusage and classify whether it means logical format/issue, concrete file, or both.book_fileIDs where possible.Does this project require a migration?
Yes, but it should be a contained migration: create a format/issue record for each current
book_file-style representation, then create one or more child file records under it.Migration requirements:
book_fileidentifiers where possible.book_filerow.book_fileshape or keep a compatibility table/view.Is this project in an experiment or feature flagged?
The database migration itself should not be user-toggleable, but UI and API surfaces that expose nested file details can be rolled out gradually. During rollout, Grimmory should continue to serve existing book/file responses until downstream clients and feature work have moved to the new model.
Success Criteria
How will you validate the solution is working correctly?
What monitoring and alerting will you do to ensure this project doesn’t decrease performance and reliability?
All reactions