-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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: refactor crud repository methods #38144
chore: refactor crud repository methods #38144
Conversation
WalkthroughThe changes introduce a new method Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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)
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceStorageStructureRepositoryCEImpl.java (1)
27-30
: Consider adding error handling for non-unique results.The
.one()
operator assumes unique results. Consider using.singleOrEmpty()
or adding error handling for cases where multiple results might exist.- return queryBuilder().criteria(q).one(); + return queryBuilder().criteria(q) + .singleOrEmpty() + .switchIfEmpty(Mono.error(new RuntimeException( + "Multiple records found for datasourceId: " + datasourceId + + " and environmentId: " + environmentId)));
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceStorageStructureRepositoryCE.java
(1 hunks)app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceStorageStructureRepositoryCEImpl.java
(2 hunks)app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/DatasourceStorageStructureRepositoryCE.java
(1 hunks)
🔇 Additional comments (2)
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/DatasourceStorageStructureRepositoryCE.java (1)
6-10
: LGTM! Clean repository interface structure.
The addition of @repository annotation and the simplified interface structure follows Spring best practices.
app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/ce/CustomDatasourceStorageStructureRepositoryCE.java (1)
11-11
: LGTM! Verify method usage patterns.
The new method signature follows reactive programming patterns correctly.
Let's verify the usage patterns of this method:
✅ Verification successful
Method usage pattern is consistent and well-integrated
The method is properly used across the codebase:
- Called by DatasourceStructureServiceCEImpl for structure retrieval
- Follows same pattern as DatasourceStorageRepositoryCE's identical method
- Correctly implemented in CustomDatasourceStorageStructureRepositoryCEImpl
- Used consistently in DatasourceStorageServiceCEImpl with proper environment ID handling
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for all calls to findByDatasourceIdAndEnvironmentId
rg -t java "findByDatasourceIdAndEnvironmentId" --no-heading
Length of output: 1827
@Override | ||
public Mono<DatasourceStorageStructure> findByDatasourceIdAndEnvironmentId( | ||
String datasourceId, String environmentId) { | ||
final BridgeQuery<DatasourceStorageStructure> q = Bridge.<DatasourceStorageStructure>equal( | ||
DatasourceStorageStructure.Fields.datasourceId, datasourceId) | ||
.equal(DatasourceStorageStructure.Fields.environmentId, environmentId); | ||
return queryBuilder().criteria(q).one(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Add compound index for datasourceId and environmentId
The DatasourceStorageStructure entity lacks a unique compound index for datasourceId and environmentId fields, which could lead to duplicate entries. Add the following annotation to ensure data integrity:
@CompoundIndex(def = "{'datasourceId': 1, 'environmentId': 1}", unique = true)
- Location:
app/server/external/src/main/java/com/appsmith/external/models/DatasourceStorageStructure.java
🔗 Analysis chain
LGTM! Verify unique constraint enforcement.
The implementation correctly uses the Bridge pattern for query construction.
Let's verify the unique constraint enforcement:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for unique index or constraint definitions
rg -t java "datasourceId.*environmentId.*unique" --no-heading
Length of output: 63
Script:
#!/bin/bash
# Search for unique index or constraint definitions in MongoDB documents
ast-grep --pattern 'class DatasourceStorageStructure {
$$$
@Index($$$)
$$$
}'
# Search for unique index definitions in repository configuration
rg -t java "@Index.*datasourceId.*environmentId" -A 2 -B 2
# Search for compound index definitions
rg -t java "CompoundIndex.*datasourceId.*environmentId" -A 2 -B 2
Length of output: 214
Script:
#!/bin/bash
# Find and examine the DatasourceStorageStructure entity class
fd -e java "DatasourceStorageStructure.java" --exec cat {}
# Look for MongoDB index configurations in repository configuration files
fd -e java "MongoConfig" --exec cat {}
Length of output: 14924
## Description As part of transaction support in PG, we are moving from using the jpa methods for database operations. This PR is refactoring the code to use custom repository class for DatasourceStorageStructureRepository from the default CrudRepository. ## Automation /ok-to-test tags="@tag.Datasource" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/12310505479> > Commit: f226809 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12310505479&attempt=2" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Datasource` > Spec: > <hr>Fri, 13 Dec 2024 07:34:38 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** - Introduced a method to retrieve `DatasourceStorageStructure` based on datasource and environment identifiers. - **Bug Fixes** - Simplified the structure of the `DatasourceStorageStructureRepositoryCE` interface by removing an outdated method. - **Documentation** - Added `@Repository` annotation to the `DatasourceStorageStructureRepositoryCE` interface to indicate its role as a Spring Data repository. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Description
As part of transaction support in PG, we are moving from using the jpa methods for database operations. This PR is refactoring the code to use custom repository class for DatasourceStorageStructureRepository from the default CrudRepository.
Automation
/ok-to-test tags="@tag.Datasource"
🔍 Cypress test results
Tip
🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/12310505479
Commit: f226809
Cypress dashboard.
Tags:
@tag.Datasource
Spec:
Fri, 13 Dec 2024 07:34:38 UTC
Communication
Should the DevRel and Marketing teams inform users about this change?
Summary by CodeRabbit
New Features
DatasourceStorageStructure
based on datasource and environment identifiers.Bug Fixes
DatasourceStorageStructureRepositoryCE
interface by removing an outdated method.Documentation
@Repository
annotation to theDatasourceStorageStructureRepositoryCE
interface to indicate its role as a Spring Data repository.