From e44a81e03175b0922fbda4036c6c2c2a5bfd238a Mon Sep 17 00:00:00 2001 From: Anagh Hegde Date: Wed, 23 Mar 2022 09:03:39 +0530 Subject: [PATCH] fix: Reconnect application showing for existing datasources due to missing flag value (#12034) * Add migration to fix the reconnect application showing for existing datasources * Changes per review * Check the invalids before adding the configured flag * Fix NPE in migration * Refactor Co-authored-by: Abhijeet --- .../appsmith/server/helpers/GitFileUtils.java | 1 + .../server/migrations/DatabaseChangelog.java | 1 - .../server/migrations/DatabaseChangelog2.java | 28 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitFileUtils.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitFileUtils.java index cae95905a9..cca0f20f08 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitFileUtils.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitFileUtils.java @@ -258,6 +258,7 @@ public class GitFileUtils { // Don't commit application name as while importing we are using the repoName as application name application.setName(null); application.setPublishedPages(null); + application.setSlug(null); } private void removeUnwantedFieldsFromDatasource(Datasource datasource) { diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/DatabaseChangelog.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/DatabaseChangelog.java index 61088d899a..8c7c515380 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/DatabaseChangelog.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/DatabaseChangelog.java @@ -5073,5 +5073,4 @@ public class DatabaseChangelog { } } - } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/DatabaseChangelog2.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/DatabaseChangelog2.java index 45d5ce3478..c31855d8e6 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/DatabaseChangelog2.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/DatabaseChangelog2.java @@ -1,6 +1,8 @@ package com.appsmith.server.migrations; +import com.appsmith.external.models.Datasource; import com.appsmith.external.models.Property; +import com.appsmith.external.models.QDatasource; import com.appsmith.server.domains.NewAction; import com.appsmith.server.domains.Plugin; import com.appsmith.server.domains.QNewAction; @@ -27,6 +29,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import static com.appsmith.server.repositories.BaseAppsmithRepositoryImpl.fieldName; +import static java.lang.Boolean.TRUE; import static org.springframework.data.mongodb.core.query.Criteria.where; import static org.springframework.data.mongodb.core.query.Query.query; @@ -609,5 +612,30 @@ public class DatabaseChangelog2 { } } + /** + * Insert isConfigured boolean to check if the datasource is correctly configured. This field will be used during + * the file or git import to maintain the datasource configuration state + * + * @param mongockTemplate + */ + @ChangeSet(order = "004", id = "add-isConfigured-flag-for-all-datasources", author = "") + public void updateIsConfiguredFlagForAllTheExistingDatasources(MongockTemplate mongockTemplate) { + final Query datasourceQuery = query(where(fieldName(QDatasource.datasource.deleted)).ne(true)) + .addCriteria(where(fieldName(QDatasource.datasource.invalids)).size(0)); + datasourceQuery.fields() + .include(fieldName(QDatasource.datasource.id)); + + List datasources = mongockTemplate.find(datasourceQuery, Datasource.class); + for(Datasource datasource: datasources) { + final Update update = new Update(); + update.set(fieldName(QDatasource.datasource.isConfigured), TRUE); + mongockTemplate.updateFirst( + query(where(fieldName(QDatasource.datasource.id)).is(datasource.getId())), + update, + Datasource.class + ); + } + } + }