Skip to content

Refactor: Normalize Database Schema with Libraries Table (fixes #86) #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

arabold
Copy link
Owner

@arabold arabold commented May 6, 2025

This PR implements the normalization of the database schema by introducing a new libraries table and updating the documents table (and related components) to reference libraries via a foreign key (library_id).

Summary of changes:

  • Added migration to create the libraries table and update documents to use library_id.
  • Refactored DocumentStore to use library_id internally, preserving the public API.
  • Updated all prepared statements and queries to join with the libraries table.
  • Updated and simplified tests to match the new schema and improved mocking guidelines.
  • Improved testing conventions in ARCHITECTURE.md to focus on public API and robust mocking.
  • Added migration and test for schema normalization.
  • Updated documentation to reflect the new schema and testing approach.

Closes #86.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR normalizes the database schema by introducing a dedicated libraries table and updating the documents table and related queries to reference libraries via a foreign key.

  • Added migration for creating the libraries table and updating documents with library_id.
  • Refactored DocumentStore to use library_id in most queries and prepared statements while leaving the documents_vec table unchanged.
  • Updated tests and documentation to align with the new schema and testing guidelines.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/store/applyMigrations.test.ts Integration tests updated to validate presence of the new libraries table and library_id column
src/store/DocumentStore.ts Updated prepared statements to use library_id and added new statements for library operations
src/store/DocumentStore.test.ts Adjusted tests and mocks to account for library_id and new library insertion behaviors
db/migrations/002-normalize-library-table.sql Migration script added to normalize the schema by introducing the libraries table and linking it
ARCHITECTURE.md Documentation updated for improved testing conventions and guidance on public API focus
Comments suppressed due to low confidence (1)

src/store/DocumentStore.ts:124

  • [nitpick] The documents_vec table still uses the legacy 'library' column while the normalization introduces 'library_id' in documents; consider updating documents_vec to use library_id for consistency across the schema.
INSERT INTO documents_vec (rowid, library, version, embedding) VALUES (?, ?, ?, ?)

@arabold arabold force-pushed the refactor/86-normalize-database-schema branch 2 times, most recently from a2e7b33 to defbf02 Compare May 17, 2025 14:37
arabold added 2 commits May 17, 2025 13:39
- Added migration to introduce libraries table and update documents to use library_id foreign key
- Refactored DocumentStore to use library_id internally, preserving public API
- Updated all prepared statements and queries to join with libraries table
- Updated and simplified tests to match new schema and mocking guidelines
- Improved testing conventions in ARCHITECTURE.md to focus on public API and robust mocking
- Added migration and test for schema normalization
- Updated documentation to reflect new schema and testing approach
…solution

Ensure the batching test for addDocuments correctly mocks the library id lookup and re-instantiates DocumentStore after patching the mock, preventing StoreError for test-lib-large-batch. This makes the test robust and prevents false negatives when batching embeddings.
@arabold arabold force-pushed the refactor/86-normalize-database-schema branch from defbf02 to 1e24cf2 Compare May 17, 2025 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor: Normalize Database Schema with Libraries Table
1 participant