Skip to content
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

Updating the setup script to handle sample data import for Docker #2751

Conversation

VanshikaSabharwal
Copy link

@VanshikaSabharwal VanshikaSabharwal commented Dec 9, 2024

What kind of change does this PR introduce?
bugfix, feature

Issue Number:

Fixes #2270

Did you add tests for your changes?

No

Snapshots/Videos:

Screenshot 2024-12-08 183611

If relevant, did you update the documentation?

Summary
This PR addresses the following issues:

  • Set up a script to start Docker and import sample data.
  • Enabled accessible ports for the localhost.
  • Ensured containers can now communicate with each other.

These changes improve the developer experience by simplifying the environment setup and ensuring seamless container interactions.

Does this PR introduce a breaking change?
No

Other information

None

Have you read the contributing guide?

Yes

Summary by CodeRabbit

  • New Features

    • Introduced a new collection for venues, including details for four distinct venues.
    • Enhanced data handling capabilities to support the new venue collection.
    • Improved setup process for Docker, including user prompts and MongoDB readiness checks.
  • Bug Fixes

    • Updated volume mapping for the Caddy service to improve configuration loading.
  • Documentation

    • Updated interfaces and enums to include the new "Venue" value.
  • Chores

    • Modified utility scripts to incorporate the new venue model for data insertion and removal processes.
    • Updated test cases for volunteer ranks to reflect correct expected values.

Copy link

coderabbitai bot commented Dec 9, 2024

Walkthrough

The changes in this pull request involve updates to several files, primarily focusing on the integration of a new "Venue" entity into the system. The docker-compose.dev.yaml file has been modified to adjust the volume mapping for the Caddy service. A new JSON file for venue data has been introduced, and the SampleData interface and schema have been updated to include "Venue" as a valid collection type. Additionally, the loadSampleData and removeSampleOrganizationUtil utilities have been updated to handle the new "Venue" model. The setup.ts file has also been enhanced to improve Docker handling and user prompts.

Changes

File Change Summary
docker-compose.dev.yaml Updated volume mapping for caddy service to use a relative path for the Caddyfile.
sample_data/venue.json Added a new JSON file containing an array of venue objects with attributes like _id, name, etc.
src/models/SampleData.ts Updated collectionName to include "Venue" in the interface and Mongoose schema.
src/utilities/loadSampleData.ts Integrated the Venue model into data insertion and document count checking functionalities.
src/utilities/removeSampleOrganizationUtil.ts Added Venue model to handle documents in the removeSampleOrganization function.
setup.ts Enhanced Docker handling with new prompts, error handling, and integration of sample data import logic.

Assessment against linked issues

Objective Addressed Explanation
Prompt user for data import if Docker is running (2270) No changes made to the setup script behavior.
Store previous Docker-related answers (2270) No implementation for storing user responses.
Ensure sample data is correctly imported when using Docker (2270) No changes made to the importation process.
Update INSTALLATION.md for Docker usage (2270) No updates to the documentation were included.

Possibly related issues

  • getVolunteerRanks test is failing  #2703: The changes in the tests/resolvers/Query/getVolunteerRanks.spec.ts file may address the failing test issue mentioned, as they involve updating expected values which could resolve discrepancies leading to test failures.

Possibly related PRs

Suggested reviewers

  • palisadoes

Poem

In the garden where venues bloom,
New paths are set, dispelling gloom.
Caddy's map now leads the way,
With data fresh, we dance and play.
A hop, a skip, a joyful cheer,
For every venue, we hold dear! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Dec 9, 2024

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Congratulations on making your first PR! 🎊 If you haven't already, check out our Contributing Guidelines and PR Reporting Guidelines to ensure that you are following our guidelines for contributing and creating PR.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
src/utilities/loadSampleData.ts (2)

132-134: Consider adding data validation for venue documents

While the implementation follows the existing pattern, consider adding validation before insertion to ensure data integrity.

 case "venue":
+  // Validate venue documents before insertion
+  const validVenues = docs.filter(doc => 
+    doc.name && typeof doc.name === 'string' &&
+    (!doc.capacity || typeof doc.capacity === 'number')
+  );
+  if (validVenues.length !== docs.length) {
+    console.warn("\x1b[33m", `Warning: ${docs.length - validVenues.length} invalid venue documents were skipped`);
+  }
-  await Venue.insertMany(docs);
+  await Venue.insertMany(validVenues);
   break;

179-179: Consider maintaining alphabetical order for collections

The venue entry seems arbitrarily placed between posts and appUserProfiles. Consider maintaining alphabetical order for better maintainability.

-      { name: "posts", model: Post },
-      { name: "venue", model: Venue },
-      { name: "appUserProfiles", model: AppUserProfile },
+      { name: "appUserProfiles", model: AppUserProfile },
+      { name: "posts", model: Post },
+      { name: "venue", model: Venue },
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 740ca31 and df0949d.

📒 Files selected for processing (5)
  • docker-compose.dev.yaml (1 hunks)
  • sample_data/venue.json (1 hunks)
  • src/models/SampleData.ts (2 hunks)
  • src/utilities/loadSampleData.ts (4 hunks)
  • src/utilities/removeSampleOrganizationUtil.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • sample_data/venue.json
🔇 Additional comments (5)
src/utilities/removeSampleOrganizationUtil.ts (1)

7-7: LGTM! Verify Venue model deletion behavior.

The addition of the Venue model follows the existing pattern consistently.

Let's verify the Venue model's integration:

Also applies to: 31-31

✅ Verification successful

Let me gather more information about the Venue model's integration with sample data and deletion behavior.


Based on the results, I can now generate the final response:

Venue model deletion behavior is properly integrated

The Venue model is correctly integrated into the sample data cleanup process:

  • It's properly imported and included in the collection models
  • The InterfaceSampleData interface includes "Venue" as a valid collection name
  • The model follows the standard schema pattern with required organization reference
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if Venue model is properly referenced in sample data
ast-grep --pattern 'interface InterfaceSampleData {
  $$$
  collectionName: $$$"Venue"$$$
}'

# Verify Venue model's schema definition
ast-grep --pattern 'const $_ = new Schema({
  $$$
})'

Length of output: 22525


Script:

#!/bin/bash
# Check Venue model's usage in removeSampleOrganizationUtil.ts
rg -A 5 "Venue" src/utilities/removeSampleOrganizationUtil.ts

# Check for sample data interface definition
rg -A 10 "interface.*SampleData" src/

# Check for Venue model's usage in sample data
rg "Venue.*collectionName" src/

Length of output: 815

src/models/SampleData.ts (3)

14-14: LGTM! Venue type addition is consistent.

The addition of the Venue type to InterfaceSampleData interface maintains type safety.


32-40: LGTM! Improved enum readability.

The enum values have been reformatted for better readability while maintaining functionality.


Line range hint 1-1: PR changes don't match stated objectives.

The PR description and linked issue (#2270) focus on improving Docker setup script and sample data import functionality. However, the actual changes primarily involve adding the Venue model to the sample data handling system. The Docker-related improvements mentioned in the PR objectives are not reflected in these changes.

Please clarify if:

  1. This PR is targeting the wrong issue
  2. Additional changes are pending
  3. The PR description needs to be updated

Let's check for any Docker setup script changes:

src/utilities/loadSampleData.ts (1)

14-14: Verify the Venue model implementation

The import statement looks correct, but let's ensure the Venue model is properly implemented.

✅ Verification successful

The Venue model is properly implemented and exported

The verification confirms:

  • The Venue model is correctly exported in src/models/Venue.ts
  • The model has a proper schema definition with required fields (name, capacity) and optional fields (description)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the Venue model implementation and exports

# Check if Venue model exists and is exported
ast-grep --pattern 'export const Venue = $$$' src/models/*.ts

# Check the model schema
rg -A 10 'const venueSchema = new Schema' src/models/

Length of output: 1874

docker-compose.dev.yaml Show resolved Hide resolved
src/utilities/loadSampleData.ts Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 9, 2024
@Cioppolo14
Copy link
Contributor

There isn’t an issue assigned to you for this PR. Please follow the guidelines in our PR_GUIDELINES.md file. We have the procedures in place so that everyone has a fair chance of contributing. I will be closing this pull request. Please follow the procedures and resubmit when ready.

@Cioppolo14 Cioppolo14 closed this Dec 9, 2024
@palisadoes palisadoes reopened this Dec 9, 2024
@palisadoes
Copy link
Contributor

Reopening as an exception.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
tests/resolvers/Query/getVolunteerRanks.spec.ts (2)

Line range hint 40-46: Fix contradictory hour values across test cases

There are contradicting assertions about volunteer hours:

  • In the first test (allTime), user1 has 2 hours
  • In the last test (yearly), the same user1 has 8 hours
    This indicates either:
  1. A data consistency issue in the test setup
  2. Incorrect expectations in the test assertions

Please review and update the test cases to ensure consistent and correct assertions that match the expected behavior of the time-based filtering and sorting.

Also applies to: 89-93


Line range hint 1-93: Add test cases for edge cases

While the current test suite covers basic functionality, it would benefit from additional test cases for:

  • Empty result sets
  • Invalid time frames
  • Invalid sort orders
  • Malformed organization IDs
  • Large result sets with pagination

Would you like me to help generate these additional test cases?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between df0949d and 78c0530.

📒 Files selected for processing (1)
  • tests/resolvers/Query/getVolunteerRanks.spec.ts (1 hunks)
🔇 Additional comments (1)
tests/resolvers/Query/getVolunteerRanks.spec.ts (1)

Line range hint 40-46: Fix inconsistent test assertions in descending order test

The test assertions appear to be logically incorrect for a descending order sort:

Let's verify the helper function's behavior:

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 9, 2024
coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 9, 2024
@palisadoes
Copy link
Contributor

Please fix the failing tests

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 10, 2024
Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.74%. Comparing base (740ca31) to head (061a854).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2751   +/-   ##
========================================
  Coverage    97.74%   97.74%           
========================================
  Files          358      358           
  Lines        18114    18115    +1     
  Branches      2601     2600    -1     
========================================
+ Hits         17706    17707    +1     
  Misses         404      404           
  Partials         4        4           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@VanshikaSabharwal
Copy link
Author

@palisadoes I fixed the failing test and this test is failing due to changes i made in docker-compose.dev.yaml file. The change was necessary to make the ports accessible on local computer.

@palisadoes
Copy link
Contributor

Does this work with any combination of docker and non docker implementations for Talawa API and Talawa Admin?

@VanshikaSabharwal
Copy link
Author

Does this work with any combination of docker and non docker implementations for Talawa API and Talawa Admin?

@palisadoes The system is being designed to support any combination of Dockerized and non-Dockerized setups for Talawa API and Talawa Admin. If both are Dockerized, a shared network is required for communication. While contributors can set this up manually, I’m working on automating the process for a smoother experience. The design also handles mixed environments (Dockerized and non-Dockerized) by ensuring proper connections and configurations, making the setup seamless for all contributors.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 40ec8e7 and 061a854.

📒 Files selected for processing (1)
  • setup.ts (4 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
setup.ts

[error] 977-978: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

🔇 Additional comments (1)
setup.ts (1)

469-521: Function runDockerComposeWithLogs implemented correctly

The function effectively checks for the Docker daemon status and manages Docker Compose operations with appropriate timeout handling.

setup.ts Show resolved Hide resolved
setup.ts Show resolved Hide resolved
@palisadoes
Copy link
Contributor

Is this ready to be merged?

@VanshikaSabharwal
Copy link
Author

Yes @palisadoes

@palisadoes palisadoes merged commit 67c805e into PalisadoesFoundation:develop Dec 11, 2024
10 of 11 checks passed
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