Design: per-user database isolation for cloud instances #4
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Context
The current cloud instance uses a single shared SQLite database (
pagepiper.db) and a single shared vec DB (pagepiper_vecs.db) for all users. This is fine for single-user self-hosting, but a multi-user cloud deployment needs per-user isolation so one user cannot read another's documents.Design questions to resolve
Isolation strategy:
pagepiper_{user_id}.dbandpagepiper_vecs_{user_id}.dbstored in a per-user data directory. Simplest; maps well to the existing single-user design. Data dir becomesPAGEPIPER_DATA_DIR/{user_id}/.user_idforeign key on all tables — all queries filtered byuser_id. Simpler ops (one file to back up), but requires careful query auditing to prevent cross-user leaks.Recommendation: Option A. SQLite file-per-user fits the existing architecture and eliminates the possibility of cross-user data leaks from missing WHERE clauses. PAGEPIPER_DATA_DIR becomes
{base}/{user_id}/created on first login.Scope
app/config.py: makeDB_PATHandVEC_DB_PATHper-request (derived from authenticated user ID), not module-level constantsapp/api/library.py,app/api/chat.py,app/api/search.py: thread DB path through from auth contextapp/services/bm25_index.py: BM25Index must be per-user (currently a shared singleton)app/services/retriever.py: sameuser_id— wire it through as the isolation keyPAGEPIPER_DATA_DIR/{user_id}/pagepiper.db,pagepiper_vecs.db,uploads/,books/Dependencies