From 226c0720bd1633db1f52a9ad73f58b3cd558c9e0 Mon Sep 17 00:00:00 2001 From: Nidhi Date: Thu, 3 Jun 2021 09:20:47 +0530 Subject: [PATCH] Default state for mongo actions that were already configured (#4873) * Default state for mongo actions that were already configured * Clean up --- .../server/migrations/DatabaseChangelog.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) 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 030aa70595..88bb57c7d3 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 @@ -50,6 +50,7 @@ import com.appsmith.server.services.OrganizationService; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.cloudyrock.mongock.ChangeLog; import com.github.cloudyrock.mongock.ChangeSet; +import com.github.cloudyrock.mongock.decorator.impl.MongockTemplate; import com.google.gson.Gson; import com.mongodb.MongoClient; import com.mongodb.MongoException; @@ -2257,4 +2258,34 @@ public class DatabaseChangelog { // Delete all the existing mongo datasource structures by setting the key to null. mongoOperations.updateMulti(query, update, Datasource.class); } + + @ChangeSet(order = "069", id = "set-mongo-actions-type-to-raw", author = "") + public void setMongoActionInputToRaw(MongockTemplate mongockTemplate) { + + // All the existing mongo actions at this point will only have ever been in the raw format + // For these actions to be readily available to users, we need to set their input type to raw manually + // This is required because since the mongo form, the default input type on the UI has been set to FORM + Plugin mongoPlugin = mongockTemplate.findOne(query(where("packageName").is("mongo-plugin")), Plugin.class); + + // Fetch all the actions built on top of a mongo database, not having any value set for input type + assert mongoPlugin != null; + List rawMongoActions = mongockTemplate.find( + query(new Criteria().andOperator( + where(fieldName(QNewAction.newAction.pluginId)).is(mongoPlugin.getId()))), + NewAction.class + ) + .stream() + .filter(mongoAction -> { + final List pluginSpecifiedTemplates = mongoAction.getUnpublishedAction().getActionConfiguration().getPluginSpecifiedTemplates(); + return pluginSpecifiedTemplates != null && pluginSpecifiedTemplates.size() == 1; + }) + .collect(Collectors.toList()); + + for (NewAction action : rawMongoActions) { + List pluginSpecifiedTemplates = action.getUnpublishedAction().getActionConfiguration().getPluginSpecifiedTemplates(); + pluginSpecifiedTemplates.add(new Property(null, "RAW")); + + mongockTemplate.save(action); + } + } }