Skip to content

Conversation

@codesungrape
Copy link
Collaborator

Description

Trello card: https://trello.com/c/5laHOgpv
Adds utility scripts and Makefile commands to manage the book database for local development.

What's included:

  • delete_books.py: Deletes all books from MongoDB directly. Exits gracefully if the collection is already empty.
  • create_books.py: Loads books from books.json, skipping duplicates.
  • Makefile commands:
    • make db-clean – delete all books
    • make db-seed – populate from JSON
    • make db-setup – clean + seed
  • Added scripts/README.md with usage instructions.
  • Linked script docs from root README.md.

Prerequisite:
Ensure MongoDB is running locally before running the scripts.

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update
  • Code refactor (improving code quality without changing functionality)

How Has This Been Tested?

CI/CD with GitHub Actions, following Red-Green-Refactor TDD approach, 100% code coverage, tested against a real MongoDB instance.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My individual commit messages are descriptive and follow our commit guidelines
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

…ext and fix logic; convert to integration test
…nd integration tests for delete_all_books and main
Copy link

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

Adds utility scripts and Makefile commands for seeding and clearing the books database, along with updated tests and documentation.

  • Introduces load_books_json helper and accompanying tests in utils/db_helpers.py
  • Adds scripts/create_books.py and scripts/delete_books.py with Makefile targets (db-seed, db-clean, db-setup)
  • Updates documentation (scripts/README.md, README.md) and CI/test runner (run_tests.sh, Makefile)

Reviewed Changes

Copilot reviewed 23 out of 26 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
utils/db_helpers.py Added JSON loader with error handling and debug print
scripts/create_books.py Script to upsert books, core logic in populate_books & entry
scripts/delete_books.py Script to delete all books (delete_all_books + CLI runner)
scripts/README.md Usage instructions for the new data management scripts
Makefile New targets for database commands and formatting/linting
README.md Updated getting started steps and project name
Comments suppressed due to low confidence (3)

scripts/create_books.py:14

  • [nitpick] Docstring mentions a bulk write operation, but the implementation performs individual upsert calls in a loop. Update the description to reflect this.
    Upserts a list of books into a collection using a bulk write operation.

scripts/README.md:41

  • The path scripts/books.json is incorrect; it should reference scripts/test_data/sample_books.json or the correct JSON file location.
| `make db-seed`  | Populates the database with the contents of `scripts/books.json`.                           |

README.md:1

  • [nitpick] The project title was changed to S_BookAPIV.2, which may be a typo. Consider using the correct repository name.
# S_BookAPIV.2

Copy link

@newmaldenite newmaldenite left a comment

Choose a reason for hiding this comment

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

Only thing I could see that looked a bit funny was that the delete_all_books helper function has a docstring that says 'deletes documents' so might need to be consistent there but all looks good :)

@codesungrape codesungrape merged commit 4737827 into main Jul 9, 2025
2 checks passed
@codesungrape codesungrape deleted the Add-scripts-to-populate-and-delete-books branch July 9, 2025 14:28
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.

3 participants