Skip to content

chore: Add mongo data migration check before initializing the postgres dump#37059

Merged
abhvsn merged 6 commits intoreleasefrom
chore/add-version-check-for-mongo-data
Nov 5, 2024
Merged

chore: Add mongo data migration check before initializing the postgres dump#37059
abhvsn merged 6 commits intoreleasefrom
chore/add-version-check-for-mongo-data

Conversation

@abhvsn
Copy link
Contributor

@abhvsn abhvsn commented Oct 24, 2024

Description

  • Enhanced data migration logic from MongoDB to Postgres, ensuring data stability before proceeding.
  • Added verification step to check for required MongoDB changeset version.

Fixes #36791

/test Sanity

🔍 Cypress test results

Warning

Tests have not run on the HEAD df02162 yet


Thu, 24 Oct 2024 10:10:48 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced data migration logic from MongoDB to Postgres, ensuring data stability before proceeding.
    • Added verification step to check for required MongoDB changeset version.
  • Bug Fixes

    • Improved error handling with clearer logging for unknown arguments and missing specifications.
  • Chores

    • Maintained existing command-line argument handling and ensured proper cleanup of temporary files during migration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 24, 2024

Warning

Rate limit exceeded

@abhvsn has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 48 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Files that changed from the base of the PR and between e2bd590 and df02162.

Walkthrough

The changes in this pull request enhance the move-to-postgres.mjs script by adding a version check to ensure that MongoDB data is migrated only if it meets a specified stable version. A new constant for the minimum MongoDB changeset and a function to verify the data's version have been introduced. The control flow now includes a conditional check that exits the migration process if the data is not at the required version, alongside improved error handling and logging.

Changes

Files Change Summary
deploy/docker/fs/opt/appsmith/utils/bin/move-to-postgres.mjs Added version check for MongoDB data before migration to Postgres, introduced new constants and functions, enhanced error handling and logging.

Assessment against linked issues

Objective Addressed Explanation
Add version check for taking a dump of Mongo data (#36791)

Possibly related PRs

Suggested reviewers

  • sharat87
  • pratapaprasanna
  • AnaghHegde

🎉 In the code where data flows,
A version check now brightly glows.
From Mongo to Postgres, we migrate,
Ensuring stability, we celebrate!
With logs that guide, and errors tamed,
Our script is robust, and well-named! 🎊


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

@abhvsn abhvsn requested a review from AnaghHegde October 24, 2024 09:18
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Oct 24, 2024
@abhvsn abhvsn marked this pull request as ready for review October 24, 2024 09:19
@github-actions github-actions bot added DB Infrastructure Pod Pod to handle database infrastructure Move to Postgres Issues required to be solved for the move to Postgres as repository layer Task A simple Todo labels Oct 24, 2024
Copy link
Contributor

@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 (1)
deploy/docker/fs/opt/appsmith/utils/bin/move-to-postgres.mjs (1)

21-24: Document the version mapping in comments.

The constant MINIMUM_MONGO_CHANGESET represents v1.43, but this mapping isn't clear from the code. Consider adding a comment that explicitly states this relationship.

 // The minimum version of the MongoDB changeset that must be present in the mongockChangeLog collection to run this script.
 // This is to ensure we are migrating the data from the stable version of MongoDB.
+// This changeset corresponds to MongoDB version 1.43
 const MINIMUM_MONGO_CHANGESET = "add_empty_policyMap_for_null_entries";
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0b93768 and 7573c3a.

📒 Files selected for processing (1)
  • deploy/docker/fs/opt/appsmith/utils/bin/move-to-postgres.mjs (3 hunks)

Copy link
Contributor

@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: 1

🧹 Outside diff range and nitpick comments (1)
deploy/docker/fs/opt/appsmith/utils/bin/move-to-postgres.mjs (1)

85-92: Consider adding success logging for version check.

The error handling looks good, but adding a success log would improve observability.

 if (!await isMongoDataMigratedToStableVersion(mongoDb)) {
   console.error("MongoDB migration check failed: Try upgrading the Appsmith instance to latest before opting for data migration.");
   console.error(`Could not find the valid migration execution entry for "${MINIMUM_MONGO_CHANGESET}" in the "${MONGO_MIGRATION_COLLECTION}" collection.`);
   await mongoClient.close();
   mongoServer?.kill();
   process.exit(1);
+} else {
+  console.log("MongoDB version check passed. Proceeding with migration...");
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7573c3a and e2bd590.

📒 Files selected for processing (1)
  • deploy/docker/fs/opt/appsmith/utils/bin/move-to-postgres.mjs (3 hunks)
🔇 Additional comments (1)
deploy/docker/fs/opt/appsmith/utils/bin/move-to-postgres.mjs (1)

19-24: LGTM! Well-defined constants with clear purpose.

The constants are appropriately named and documented, clearly indicating their role in version checking.

const sortedCollectionNames = collectionNames.map(collection => collection.name).sort();

// Verify that the MongoDB data has been migrated to a stable version i.e. v1.43 before we start migrating the data to Postgres.
if (!await isMongoDataMigratedToStableVersion(mongoDb)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this logic to the isMongoDataMigratedToStableVersion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any reason for this ask? As the method suggests it only checks if the mongo data is migrated to correct changeId before starting the migration. Also if we go other route then instead of passing only the mongo client we will have to pass mongoServer as well which is not necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool works. Just wanted to keep all the changes related to version in a single method.

@abhvsn abhvsn requested a review from AnaghHegde October 28, 2024 12:38
@abhvsn abhvsn merged commit 6dc6194 into release Nov 5, 2024
@abhvsn abhvsn deleted the chore/add-version-check-for-mongo-data branch November 5, 2024 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DB Infrastructure Pod Pod to handle database infrastructure Move to Postgres Issues required to be solved for the move to Postgres as repository layer skip-changelog Adding this label to a PR prevents it from being listed in the changelog Task A simple Todo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task]: Add version check for taking a dump of Mongo data

2 participants