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

chore: autocommit migration for annotation and embedded datasource changes. #36261

Merged
merged 4 commits into from
Sep 16, 2024

Conversation

sondermanish
Copy link
Contributor

@sondermanish sondermanish commented Sep 11, 2024

Description

  • Added autocommit migration to avoid uncommited changes on some of the applications.

Fixes #Issue Number
or
Fixes Issue URL

Automation

/ok-to-test tags="@tag.Git"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/10878546679
Commit: 0013cde
Cypress dashboard.
Tags: @tag.Git
Spec:


Mon, 16 Sep 2024 06:42:16 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Updated the server version from 10 to 11, enhancing compatibility and functionality related to JSON schema handling.
    • Improved logic for default REST datasource migrations, making it more robust and accessible.
    • Added support for SSH connection configurations in datasource management.
  • Bug Fixes

    • Added null checks to prevent potential errors during datasource migrations, enhancing overall reliability.
  • Refactor

    • Streamlined filtering logic for actions, improving code readability and maintainability.

Copy link
Contributor

coderabbitai bot commented Sep 11, 2024

Walkthrough

The pull request introduces substantial modifications to the migration logic for application JSON schemas, specifically updating the handling of schema versions and datasource migrations. Key changes include restructuring the flow of the migrateApplicationJsonToLatestSchema method, incrementing the server version from 10 to 11, and enhancing the accessibility and robustness of methods related to default REST datasource migrations. The overall goal is to improve the clarity, maintainability, and reliability of the migration process.

Changes

File Path Change Summary
app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/JsonSchemaMigration.java Restructured migration logic to update ServerSchemaVersion systematically and simplified version handling in nonReactiveServerMigrationForImport.
app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/JsonSchemaVersionsFallback.java Updated serverVersion from 10 to 11, indicating a version increment for compatibility.
app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/MigrationHelperMethods.java Changed method visibility from private to public for conditionForDefaultRestDatasource and added null checks to enhance reliability.
app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/utils/JsonSchemaMigrationHelper.java Refactored filtering logic for actions to use a method reference for improved readability.
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/DatasourceConfiguration.java Added new fields sshProxy and sshProxyEnabled to support SSH connection configurations.

Possibly related PRs

Poem

In the realm of code, a change was made,
Migration paths, now clearer laid.
From version ten to eleven we soar,
With checks in place, we’ll crash no more!
A dance of logic, both robust and bright,
Our schemas now shine, a beautiful sight! 🌟


Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 49bcb9e and 0013cde.

Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/JsonSchemaMigration.java (2 hunks)
Additional comments not posted (2)
app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/JsonSchemaMigration.java (2)

70-87: Excellent job documenting the migration process! 📝

The comment provides a clear and detailed explanation of the migration process for handling uncommitted changes in Embedded REST API datasource URLs. It helps future maintainers understand the rationale behind the migration and the steps involved.

The code that checks the server schema version and updates it from 9 to 10 is a logical part of the migration process.


206-210: The migration logic for server schema versions 9 and 10 looks good! 👍

The code correctly updates the server schema version from 9 to 10 and then handles the version 10 migration by calling the migrateApplicationJsonToVersionTen method with an empty map. Finally, it updates the server schema version to 11.

This ensures a smooth migration process for the specified versions.


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 generate interesting stats about this repository and render them as a table.
    -- @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.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Sep 11, 2024
@sondermanish sondermanish added the ok-to-test Required label for CI label Sep 11, 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: 0

Outside diff range and nitpick comments (2)
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/DatasourceConfiguration.java (1)

40-40: Nice addition of the sshProxyEnabled field! 🙌

The sshProxyEnabled field of type Boolean is a great complement to the sshProxy field. It provides a convenient way to control whether the SSH proxy is enabled or not, allowing for more flexible configuration options.

The use of the @JsonView annotation with Views.Public and FromRequest ensures that the field is properly included in the relevant JSON serialization views.

As a small suggestion, consider adding a default value for the sshProxyEnabled field, such as false, to provide a clear initial state when the field is not explicitly set.

@JsonView({Views.Public.class, FromRequest.class})
-Boolean sshProxyEnabled;
+Boolean sshProxyEnabled = false;
app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/MigrationHelperMethods.java (1)

Line range hint 1326-1368: Great job implementing the setDatasourceConfigDetailsInDefaultRestDatasourceForActions method! It provides a way to set the datasource configuration details for actions with default REST datasources.

The method serves a specific purpose and handles different scenarios effectively:

  1. It takes a NewAction object and a map of gitSyncId to NewAction as parameters.
  2. It retrieves the action's unpublished action and datasource.
  3. It checks if the defaultDatasourceActionMap contains an entry for the action's gitSyncId.
  4. If an entry exists, it retrieves the corresponding action from the map and sets the datasource configuration URL from that action, if the datasource configuration is not null.
  5. If no entry exists or the datasource configuration from the map is null, it sets the URL to an empty string.

The method includes null checks to avoid potential null pointer exceptions and ensures that the datasource configuration is set only if it is not null to prevent uncommitted changes. This approach helps maintain data integrity and avoids unintended modifications.

To further improve the method, consider handling the case when the datasource configuration from the map is null. Instead of returning early, you could set the URL to an empty string, similar to the case when no entry exists in the map. This would ensure consistent behavior and avoid leaving the datasource configuration unset. Here's an example:

if (actionFromMap.getUnpublishedAction() == null
        || actionFromMap.getUnpublishedAction().getDatasource() == null
        || actionFromMap.getUnpublishedAction().getDatasource().getDatasourceConfiguration() == null) {
    datasourceConfiguration.setUrl("");
    actionDatasource.setDatasourceConfiguration(datasourceConfiguration);
    return;
}

This way, the method would always set the datasource configuration, either with the URL from the map or an empty string, providing a more predictable outcome.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d7544bf and 32187de.

Files selected for processing (3)
  • app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/DatasourceConfiguration.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/MigrationHelperMethods.java (3 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/utils/JsonSchemaMigrationHelper.java (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/utils/JsonSchemaMigrationHelper.java
Additional comments not posted (5)
app/server/appsmith-interfaces/src/main/java/com/appsmith/external/models/DatasourceConfiguration.java (1)

37-37: Great work adding the sshProxy field! 👍

The addition of the sshProxy field of type SSHConnection is a valuable enhancement to the DatasourceConfiguration class. It allows the class to handle SSH connection configurations, which can be important for managing data sources securely.

The use of the @JsonView annotation with Views.Public and FromRequest ensures that the field is properly included in the relevant JSON serialization views.

Keep up the excellent work in expanding the functionality of the class!

app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/MigrationHelperMethods.java (4)

1240-1263: Great job refactoring the conditionForDefaultRestDatasource method! The changes make the code more robust and readable.

The key improvements are:

  1. Adding null safety checks for the action's unpublished action and datasource to prevent potential null pointer exceptions.
  2. Splitting the logic to determine if an action is a default REST datasource into two separate checks:
    • A certain check that verifies if the datasource ID is absent and the name matches DEFAULT_REST_DATASOURCE.
    • A probable check that assesses whether the action's plugin ID corresponds to either the REST API or GraphQL plugin.
  3. Returning true if either the certain check or the probable check passes, providing flexibility in identifying default REST datasources.

These changes enhance the method's reliability and maintainability. Well done!


Line range hint 1265-1274: Excellent addition of the conditionForDefaultRestDatasourceMigration method! It encapsulates the logic to determine if an action requires migration for a default REST datasource.

The method serves a clear purpose and is implemented effectively:

  1. It calls the conditionForDefaultRestDatasource method to determine if the action is a default REST datasource.
  2. It checks if the action's datasource configuration is missing or if the URL is not set.
  3. It returns true if the action is a default REST datasource and the datasource configuration or URL is missing.

The method follows a clear naming convention and is well-structured, making it easy to understand its functionality. This addition enhances the code's modularity and readability. Great work!


Line range hint 1277-1293: Great job implementing the migrateApplicationJsonToVersionTen method! It provides a clear and structured approach to migrate the application JSON to version 10.

The method serves a specific purpose and is implemented effectively:

  1. It takes an ApplicationJson object and a map of gitSyncId to NewAction as parameters.
  2. It iterates over the action list in the application JSON.
  3. For each action, it checks if the action requires migration using the conditionForDefaultRestDatasourceMigration method.
  4. If the action requires migration, it calls the setDatasourceConfigDetailsInDefaultRestDatasourceForActions method to set the datasource configuration details.

The method is well-organized and follows a logical flow, making it easy to understand and maintain. It leverages helper methods to keep the code modular and readable. This addition streamlines the migration process for version 10. Excellent work!


Line range hint 1295-1315: Excellent addition of the doesRestApiRequireMigration method! It provides a convenient way to determine if the application JSON requires migration for REST APIs.

The method serves a clear purpose and is implemented effectively:

  1. It takes an ApplicationJson object as a parameter.
  2. It iterates over the action list in the application JSON.
  3. For each action, it checks if the action requires migration using the conditionForDefaultRestDatasourceMigration method.
  4. If any action requires migration, it returns true. Otherwise, it returns false.

The method is well-structured and follows a clear logic, making it easy to understand and use. It leverages the conditionForDefaultRestDatasourceMigration method to identify actions that require migration, promoting code reuse and modularity. This addition simplifies the process of checking if migration is needed for REST APIs. Great job!

@sondermanish sondermanish added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Sep 12, 2024
@sondermanish
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10847408262.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36261.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-36261.dp.appsmith.com

applicationJsonWithMigration10.setServerSchemaVersion(10);
return applicationJsonWithMigration10;
});
if (migratedApplicationJson.getServerSchemaVersion() == 9) {
Copy link
Member

@mohanarpit mohanarpit Sep 16, 2024

Choose a reason for hiding this comment

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

@sondermanish Can you please add a comment to explain what we are doing here? I'm suggesting this because we are using magic numbers for version 9 and version 10. This is hard to understand for another reader.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added comments as suggested.

@sondermanish sondermanish added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Sep 16, 2024
@sondermanish sondermanish enabled auto-merge (squash) September 16, 2024 06:36
@sondermanish sondermanish merged commit 71261b1 into release Sep 16, 2024
46 of 48 checks passed
@sondermanish sondermanish deleted the chore/autocommit-fix branch September 16, 2024 07:54
@coderabbitai coderabbitai bot mentioned this pull request Sep 16, 2024
2 tasks
Shivam-z pushed a commit to Shivam-z/appsmith that referenced this pull request Sep 26, 2024
…anges. (appsmithorg#36261)

## Description
- Added autocommit migration to avoid uncommited changes on some of the
applications.


Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`

## Automation

/ok-to-test tags="@tag.Git"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!IMPORTANT]
> 🟣 🟣 🟣 Your tests are running.
> Tests running at:
<https://github.com/appsmithorg/appsmith/actions/runs/10878546679>
> Commit: 0013cde
> Workflow: `PR Automation test suite`
> Tags: `@tag.Git`
> Spec: ``
> <hr>Mon, 16 Sep 2024 06:20:40 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Updated the server version from 10 to 11, enhancing compatibility and
functionality related to JSON schema handling.
- Improved logic for default REST datasource migrations, making it more
robust and accessible.
- Added support for SSH connection configurations in datasource
management.

- **Bug Fixes**
- Added null checks to prevent potential errors during datasource
migrations, enhancing overall reliability.

- **Refactor**
- Streamlined filtering logic for actions, improving code readability
and maintainability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants