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

Minor Update -> reset:data #3304

Merged

Conversation

JaiPannu-IITI
Copy link

@JaiPannu-IITI JaiPannu-IITI commented Feb 26, 2025

Overview

Based on discussion about testing the scripts with xoldd, it came into light that we don't need to reset administrator and recreate (similar to what seedInitialData does), we should ignore this since it remains unaffected from users.

This PR introduces minor change in script to skip deleting administrator from DB and skip checking or recreation of administrator in both reset:data or add:sample_data since it is absolute that administrator always exist in any situation even after a db reset.

Related Issue: #3214

Future Steps

Since we are close to resolving issue regarding conflicts that might occur during parallel vitest, this PR will be followed by adding new tests and correcting old ones to avoid conflict while running in parallel.

Summary by CodeRabbit

  • Refactor
    • Streamlined database initialization and cleanup by removing explicit administrator setup checks.
    • Adjusted logging to now simply confirm that administrator access is preserved after database operations.
  • Tests
    • Updated test cases to align with the simplified database processes, eliminating scenarios related to administrator verification.

@JaiPannu-IITI JaiPannu-IITI marked this pull request as ready for review February 26, 2025 16:43
Copy link

coderabbitai bot commented Feb 26, 2025

Walkthrough

This pull request removes the ensureAdministratorExists function and its related logic from multiple database management scripts and corresponding test files. The changes simplify the control flow in the main functions by eliminating administrator existence checks and associated error handling. Additionally, modifications were made to the database formatting helper to introduce an adminEmail variable and adjust SQL queries, including filtering operations. The test suites have been updated to remove any references or assertions related to the removed administrator validation logic.

Changes

File(s) Change Summary
scripts/dbManagement/addSampleData.ts, scripts/dbManagement/resetData.ts Removed calls to ensureAdministratorExists from the main functions. In resetData.ts, replaced error handling with a log message stating "Administrator preserved."
scripts/dbManagement/helpers.ts Removed the ensureAdministratorExists function. Modified the formatDatabase function to introduce an adminEmail variable, adjust the SQL query for fetching table names, filter out the "users" table, and delete non-administrator users.
test/scripts/dbManagement/addSampleData.test.ts, test/scripts/dbManagement/resetDB.test.ts Deleted test references, mocks, and assertions related to the ensureAdministratorExists function, narrowing the test coverage to database connectivity and collection insertion/formatting scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Main as addSampleData.ts main function
    participant DB as Database
    Caller->>Main: Trigger add sample data operation
    Main->>DB: Connect to DB and insert collections
    DB-->>Main: Return success/failure
    Main-->>Caller: Return response
Loading
sequenceDiagram
    participant Caller
    participant Main as resetData.ts main function
    participant DB as Database
    Caller->>Main: Initiate database reset
    Main->>DB: Format database (truncate non-admin tables)
    DB-->>Main: Confirm formatting
    Main->>Main: Log "Administrator preserved."
    Main-->>Caller: Operation completed
Loading

Possibly related PRs

Suggested labels

ignore-sensitive-files-pr

Suggested reviewers

  • palisadoes

Tip

CodeRabbit's docstrings feature is now available as part of our Pro Plan! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b08ad21 and 13d618f.

📒 Files selected for processing (4)
  • scripts/dbManagement/helpers.ts (1 hunks)
  • scripts/dbManagement/resetData.ts (1 hunks)
  • test/scripts/dbManagement/addSampleData.test.ts (1 hunks)
  • test/scripts/dbManagement/resetDB.test.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Run tests for talawa api
  • GitHub Check: Analyse Code With CodeQL (typescript)
🔇 Additional comments (7)
scripts/dbManagement/resetData.ts (1)

28-28: Improved clarity with explicit administrator preservation message.

The newly added log message clearly communicates that the administrator account is being preserved during the reset process, which aligns with the PR's objective to skip the deletion of the administrator account.

test/scripts/dbManagement/addSampleData.test.ts (1)

57-57: Clarified test arrangement comment.

This minor change to the comment improves clarity by making the test arrangement more explicit.

test/scripts/dbManagement/resetDB.test.ts (1)

35-35: Test description updated to reflect new behavior.

The test description has been appropriately updated to remove the reference to admin creation, aligning with the PR's objective to skip administrator account handling.

scripts/dbManagement/helpers.ts (4)

69-75: Added safety check to prevent accidental deletion of all users.

The addition of the adminEmail variable and associated safety check is an excellent safeguard that prevents catastrophic data loss in case the environment variable is undefined.


77-78: Enhanced code clarity with meaningful constants.

Using a named constant for the users table improves code readability and maintainability. This is a good practice that makes the code easier to understand.


85-87: Improved database operation safety by filtering the users table.

Filtering out the users table from the list of tables to truncate is a critical change that supports the PR's objective of preserving the administrator account during resets.


99-102: Implemented targeted user deletion to preserve the administrator.

Instead of deleting all users and recreating the administrator, this approach simply preserves the administrator by only deleting other users. This is more efficient and eliminates potential issues that could arise during recreation.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
  • @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

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

@JaiPannu-IITI JaiPannu-IITI changed the title Fix -> reset:data Minor Update -> reset:data Feb 26, 2025
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: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0eef4d8 and b08ad21.

📒 Files selected for processing (5)
  • scripts/dbManagement/addSampleData.ts (1 hunks)
  • scripts/dbManagement/helpers.ts (1 hunks)
  • scripts/dbManagement/resetData.ts (1 hunks)
  • test/scripts/dbManagement/addSampleData.test.ts (0 hunks)
  • test/scripts/dbManagement/resetDB.test.ts (0 hunks)
💤 Files with no reviewable changes (2)
  • test/scripts/dbManagement/resetDB.test.ts
  • test/scripts/dbManagement/addSampleData.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Run tests for talawa api
  • GitHub Check: Analyse Code With CodeQL (typescript)
🔇 Additional comments (4)
scripts/dbManagement/resetData.ts (1)

28-28: Confirm actual presence of the admin user
While this message indicates that administrator access is preserved, there's no explicit check to ensure that the admin user exists in the system. If API_ADMINISTRATOR_USER_EMAIL_ADDRESS isn't set or is invalid, this might be misleading. Consider verifying the admin account before displaying this message.

scripts/dbManagement/addSampleData.ts (1)

3-3: Removal of ensureAdministratorExists is aligned with the new approach
Dropping the function import is consistent with the PR objective to preserve rather than recreate the admin. This clarifies that administrator creation is no longer a step in addSampleData.

scripts/dbManagement/helpers.ts (2)

69-70: Validate the adminEmail usage
Relying on envConfig.API_ADMINISTRATOR_USER_EMAIL_ADDRESS is fine, but consider enforcing a fail-fast mechanism (e.g., throwing an error) if this variable is missing. Otherwise, you risk deleting all users or preserving none.


84-90: Truncation approach looks solid
Using RESTART IDENTITY CASCADE here is a standard way to reset tables while also addressing any foreign key dependencies. The logic is clear and appropriate for a full “clean slate” reinitialization.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 26, 2025
Copy link

codecov bot commented Feb 26, 2025

Codecov Report

Attention: Patch coverage is 8.69565% with 21 lines in your changes missing coverage. Please review.

Project coverage is 48.57%. Comparing base (0eef4d8) to head (13d618f).
Report is 1 commits behind head on develop-postgres.

Files with missing lines Patch % Lines
scripts/dbManagement/helpers.ts 0.00% 21 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##           develop-postgres    #3304   +/-   ##
=================================================
  Coverage             48.56%   48.57%           
=================================================
  Files                   458      458           
  Lines                 34533    34489   -44     
  Branches                976      971    -5     
=================================================
- Hits                  16772    16752   -20     
+ Misses                17761    17737   -24     

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

@JaiPannu-IITI
Copy link
Author

JaiPannu-IITI commented Feb 26, 2025

@palisadoes Please ignore this Patch, it is related to helpers file for which tests are not written right now, xoldd told me that if any other file is conflicting in parallel tests with sample data, then it would need to be fixed rather than these helpers since files should be able to test on flexible DB states. I am working on all of this to ensure error free parallel integration tests, will raise related PR soon.

Meanwhile this PR is ready for review.

@palisadoes palisadoes merged commit 29d92be into PalisadoesFoundation:develop-postgres Feb 26, 2025
16 of 17 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.

2 participants