-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Migration for missing datasource configuration on default rest…
… datasources for git connected app. (#36203) ## Description Fixes #`Issue Number` _or_ Fixes `Issue URL` > [!WARNING] > _If no issue exists, please create an issue first, and check with the maintainers if the issue is valid._ ## Automation /ok-to-test tags="@tag.Git, @tag.ImportExport" ### 🔍 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/10789950948> > Commit: 69729ce > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10789950948&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Git, @tag.ImportExport` > Spec: > <hr>Tue, 10 Sep 2024 10:07:42 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** - Enhanced application JSON migration process to support additional contextual parameters, improving accuracy and relevance. - Introduced a new helper class to facilitate datasource configuration during migrations. - **Bug Fixes** - Improved handling of incompatible schemas during migration, ensuring robust error management. - **Tests** - Adjusted test cases to accommodate changes in method signatures for migration processes, ensuring continued functionality. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
1 parent
70a7164
commit da5d37e
Showing
8 changed files
with
269 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...-server/src/main/java/com/appsmith/server/migrations/utils/JsonSchemaMigrationHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.appsmith.server.migrations.utils; | ||
|
||
import com.appsmith.external.constants.PluginConstants; | ||
import com.appsmith.server.applications.base.ApplicationService; | ||
import com.appsmith.server.domains.Application; | ||
import com.appsmith.server.domains.NewAction; | ||
import com.appsmith.server.dtos.ApplicationJson; | ||
import com.appsmith.server.migrations.MigrationHelperMethods; | ||
import com.appsmith.server.newactions.base.NewActionService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.StringUtils; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
@Component | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class JsonSchemaMigrationHelper { | ||
|
||
private final ApplicationService applicationService; | ||
private final NewActionService newActionService; | ||
|
||
public Mono<ApplicationJson> addDatasourceConfigurationToDefaultRestApiActions( | ||
String baseApplicationId, String branchName, ApplicationJson applicationJson) { | ||
|
||
Mono<ApplicationJson> contingencyMigrationJson = Mono.defer(() -> Mono.fromCallable(() -> { | ||
MigrationHelperMethods.migrateApplicationJsonToVersionTen(applicationJson, Map.of()); | ||
return applicationJson; | ||
})); | ||
|
||
if (!StringUtils.hasText(baseApplicationId) || !StringUtils.hasText(branchName)) { | ||
return contingencyMigrationJson; | ||
} | ||
|
||
Mono<Application> applicationMono = applicationService | ||
.findByBranchNameAndBaseApplicationId(branchName, baseApplicationId, null) | ||
.cache(); | ||
|
||
return applicationMono | ||
.flatMap(branchedApplication -> { | ||
return newActionService | ||
.findAllByApplicationIdAndViewMode( | ||
branchedApplication.getId(), Boolean.FALSE, Optional.empty(), Optional.empty()) | ||
.filter(action -> { | ||
if (action.getUnpublishedAction() == null | ||
|| action.getUnpublishedAction().getDatasource() == null) { | ||
return false; | ||
} | ||
|
||
boolean reverseFlag = StringUtils.hasText(action.getUnpublishedAction() | ||
.getDatasource() | ||
.getId()) | ||
|| !PluginConstants.DEFAULT_REST_DATASOURCE.equals(action.getUnpublishedAction() | ||
.getDatasource() | ||
.getName()); | ||
|
||
return !reverseFlag; | ||
}) | ||
.collectMap(NewAction::getGitSyncId); | ||
}) | ||
.map(newActionMap -> { | ||
MigrationHelperMethods.migrateApplicationJsonToVersionTen(applicationJson, newActionMap); | ||
return applicationJson; | ||
}) | ||
.switchIfEmpty(contingencyMigrationJson) | ||
.onErrorResume(error -> { | ||
log.error("Error occurred while migrating actions of application json. {}", error.getMessage()); | ||
return contingencyMigrationJson; | ||
}); | ||
} | ||
} |
Oops, something went wrong.